4

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")

megido
  • 4,135
  • 6
  • 29
  • 33

1 Answers1

10

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))
phihag
  • 278,196
  • 72
  • 453
  • 469