Re: listing attributes

2006-02-14 Thread Thomas Girod
You are right, using __dict__ is what i needed. But I chose the solution explained before because i don't want to list all attributes of the object, only attributes that are instances of the class Property (or a subclass of it). -- http://mail.python.org/mailman/listinfo/python-list

Re: listing attributes

2006-02-14 Thread Peter Hansen
Steven D'Aprano wrote: > On Mon, 13 Feb 2006 22:18:56 -0500, Peter Hansen wrote: >>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 variabl

Re: listing attributes

2006-02-14 Thread Thomas Girod
Thanks a lot for all your answers ! Thanks to you I resolved this problem. Here is what i've done : [...] for (_,v) in getmembers(self): if isinstance(v,Property): st += "\t%s\n" % str(v) [...] as all the attributes I want to get are instances of Property or a subclass of Property,

Re: listing attributes

2006-02-14 Thread Christoph Zwerschke
Steven D'Aprano wrote: > However it is easy to use introspection to get what you need. So just for completeness sake, what Thomas probably wants is the following: from types import MethodType def attributes(obj): return [attr for attr in dir(obj) if not attr.startswith('__') and n

Re: listing attributes

2006-02-14 Thread Steven D'Aprano
On Mon, 13 Feb 2006 22:18:56 -0500, Peter Hansen wrote: > 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

Re: listing attributes

2006-02-13 Thread Evan Monroig
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

Re: listing attributes

2006-02-13 Thread James Stroud
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. > > In fact, all my variables are referencing to objects of the sa

Re: listing attributes

2006-02-13 Thread Peter Hansen
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