getting all user defined attributes of a class

Amit Gupta emailamit at gmail.com
Thu Feb 7 13:42:52 EST 2008


On Feb 7, 12:28 am, grflanagan <grflana... at yahoo.co.uk> wrote:
> On Feb 6, 11:07 pm, Amit Gupta <emaila... at gmail.com> wrote:
>
> > Hi
>
> > How do I get user defined attributes of a class? e.g
>
> > Class A(object) :
> >   self.x = 1
> > ------------------
>
> > I want something like:
> >   for userattrib in A.getAllUserAttribute() :
> >     print userattrib
[..]
>
> HTH
>
> Gerard

Thanks. What I found is: If I call iterate over the __dict__ of the
instance of the class, I only get user-atttributes and not built-in
attributes. I have an instance of that class, anyway, so this will do.
However, I wonder if I am getting just lucky and this might change in
future. In that regard the solution provides by all posters above
might well be more robust.

A



More information about the Python-list mailing list