Created
September 15, 2023 13:30
-
-
Save ayharano/82a0d19e873b2af0f84db8236d840510 to your computer and use it in GitHub Desktop.
List methods and attributes for a Python object instance
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> class X: | |
... def __init__(self): | |
... self._a = None | |
... @property | |
... def a(self): | |
... return self._a | |
... @a.setter | |
... def a(self, val): | |
... self._a = val | |
... | |
>>> x = X() | |
>>> obj = x | |
>>> [x for x in dir(obj) if not callable(getattr(obj, x))] # attributes | |
['__dict__', '__doc__', '__module__', '__weakref__', '_a', 'a'] | |
>>> [x for x in dir(obj) if callable(getattr(obj, x))] # methods | |
['__class__', '__delattr__', '__dir__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getstate__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment