listing attributes

Evan Monroig evan.monroig at gmail.com
Mon Feb 13 22:06:40 EST 2006


On Feb.13 18h37, Thomas Girod wrote :
> Hi there.
> 
> I'm trying to get a list of attributes from a class. The dir() function
> seems to be convenient, but unfortunately it lists to much - i don't
> need the methods, neither the built-in variables.

If you do something like this you should have a list of attributes:

l = dir(object)
l = [s for s in l if s[:2] != '__']
l = [s for s in l if not callable(getattr(object, s))]

cheers,

Evan



More information about the Python-list mailing list