I'm trying to gather all the name
attributes of my class' members:
from anytree import Node, RenderTree
class Tree:
config = Node('configure')
# other class variables...
def get_all_members(self):
# tried this option first
members = [attr for attr in dir(self) if not callable(getattr(self, attr)) and not attr.startswith("__")]
# and then deleted first option and tried this option
members = vars(Tree)
return members
I've tried both of these methods that I've seen here but the 1st is giving me names of all members. The second is giving the members themselves, but in a list, and I want to have a specific attribute. I tried something like
members = [name for name in vars(Tree).name]
but that gives me
members = [name for name in vars(Tree).name]
How can I achieve my goal here?
Just to show name
is one of config
's attributes: dir(config)
will result:
['_NodeMixin__attach', '_NodeMixin__check_loop', '_NodeMixin__detach', 'class', 'delattr', 'dict', 'dir', 'doc', 'eq', 'format', 'ge', 'getattribute', 'gt', 'hash', 'init', 'le', 'lt', 'module', 'ne', 'new', 'reduce', 'reduce_ex', 'repr', 'setattr', 'sizeof', 'str', 'subclasshook', 'weakref', '_children', '_name', '_parent', '_path', '_post_attach', '_post_detach', '_pre_attach', '_pre_detach', 'anchestors', 'children', 'depth', 'descendants', 'height', 'is_leaf', 'is_root', 'name', 'parent', 'path', 'root', 'separator', 'siblings']