For example I have next python class
class Myclass():
a = int
b = int
Imagine that I don't know the name this class, so I need to get the names of attributes? ("a" and "b")
If you want all (including private) attributes, just
dir(Myclass)
Attributes starting with _
are private/internal, though. For example, even your simple Myclass
will have a __module__
and an empty __doc__
attribute. To filter these out, use
filter(lambda aname: not aname.startswith('_'), dir(Myclass))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With