dir
dir([object]) -> list of strings
If called without an argument, return the names in the current scope.
Else, return an alphabetized list of names comprising (some of) the
attributes of the given object, and of attributes reachable from it.
If the object supplies a method named __dir__, it will be used;
otherwise the default dir() logic is used and returns:
for a module object: the module's attributes.
for a class object: its attributes, and recursively the attributes
of its bases.
for any other object: its attributes, its class's attributes, and
recursively the attributes of its class's base classes.
Pleaes define a demo class called TestClass as follow.
>>> class TestClass(object):
... def abc(self):
... print('Hello ABC !')
...
... def xyz(self):
... print('Hello xyz !')
...
>>> dir(TestClass)
['__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'abc', 'xyz']
getattr
getattr(object, name[, default]) -> value
Get a named attribute from an object;
getattr can get a attribute from TestClass:
>>> getattr(TestClass, 'abc')
<unbound method TestClass.abc>
>>> getattr(TestClass, 'xxx', 'Invalid-attr')
'Invalid-attr'
hasattr
hasattr(object, name) -> bool
Return whether the object has an attribute with the given name.
demo:
>>> hasattr(TestClass, 'abc')
True
>>> hasattr(TestClass, 'xxx')
False
If nothing can help you, please make your idea clear.