getting all user defined attributes of a class

Amit Gupta emailamit at gmail.com
Wed Feb 6 18:16:26 EST 2008


On Feb 6, 2:55 pm, "Diez B. Roggisch" <de... at nospam.web.de> wrote:
> Amit Gupta schrieb:
>
>
>
> > On Feb 6, 2:15 pm, Marc 'BlackJack' Rintsch <bj_... at gmx.net> wrote:
> >> On Wed, 06 Feb 2008 14:07:23 -0800, Amit Gupta wrote:
> >>> Class A(object) :
> >>>   self.x = 1
> >> This is not valid Python code.
>
> >>> I want something like:
> >>>   for userattrib in A.getAllUserAttribute() :
> >>>     print userattrib
> >>> My question is, is there a builtin function, called
> >>> getAllUserAttributes?
> >> No and there can't be since the attributes you seem to be interested in
> >> don't exist until an instance is created.
>
> >> Ciao,
> >>         Marc 'BlackJack' Rintsch
>
> > My mistake:
>
> > I should make class A as:
> > class A (object) :
> >   x = 1
>
> > Now, x is class attribute and I am looking for some-way to filter non-
> > user-defined attributes.
>
> > e.g.g if I do
> > for attr in a.__dict__ :
> >   print attr
>
> > I will also get
>
> > __module__, __weakref__ and others including "x"
>
> Just create an empty class, gather all attribute names from that and
> then subtract that set of names from the names you get from a "real" class.
>
> Dize

Fine. This is a hack. I am looking if python language itself provides
any built-in function for this. E.g.:

When I do help on some built-in function, it displays that function is
built_in. Can that information get accessed using a function? (now,
don't ask me to store help-output in buffer and grep for built-in).


A



More information about the Python-list mailing list