Dec-22-2017, 01:42 AM
You can do it with inspect:
class MyTestClass: def __init__(self): self.list1 = [ ] self.fptr = self.method_a self.mamals = { 'rat': {'has_tail': True}, 'dog': {'has_tail': True}, 'guppy': {'has_tail': False, 'has_fin': True} } self.fptr() def method_a(self): pass def try_me(): import inspect from pprint import pprint mtc = MyTestClass() # Get everything for name, member in inspect.getmembers(mtc): if name.startswith('__'): continue pprint(f'name: {name}, member: {member}') if __name__ == "__main__": try_me()output:
Output:('name: fptr, member: <bound method MyTestClass.method_a of '
'<__main__.MyTestClass object at 0x00000000028CBE10>>')
'name: list1, member: []'
("name: mamals, member: {'rat': {'has_tail': True}, 'dog': {'has_tail': True}, "
"'guppy': {'has_tail': False, 'has_fin': True}}")
('name: method_a, member: <bound method MyTestClass.method_a of '
'<__main__.MyTestClass object at 0x00000000028CBE10>>')