find_attrs¶
- emlib.misc.find_attrs(obj, excludeprefix='_')[source]¶
Iterate over all attributes of objects.
- Parameters:
obj – the object to query
excludeprefix – attributes starting with this prefix will be excluded
- Return type:
list
[str
]- Returns:
a list of all the attibutes (instance variables) of this object. Notice that results are cached by class so if an object has dynamic attributes these will not be detected
Note
This function will only return attributes, no methods, class variables, staticmethods, etc.
Example
>>> class Foo: ... def __init__(self, a, b): ... self.a = a ... self.b = b ... >>> class Bar(Foo): ... def __init__(self, c): ... super().__init__(1, 2) ... self.c = c ... >>> bar = Bar(3) >>> find_attrs(bar) ['a', 'b', 'c']