listing attributes

Peter Hansen peter at engcorp.com
Mon Feb 13 22:18:56 EST 2006


Thomas Girod wrote:
> 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.
> 
> In fact, all my variables are referencing to objects of the same type.
> Can anyone suggest me a way to get this list of variables ?

Does the __dict__ attribute help you?  (Try viewing obj.__dict__ at the 
interpreter prompt and see if it has what you expect. 
obj.__dict__.keys() would be just the names of those attributes.)

-Peter




More information about the Python-list mailing list