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
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
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,
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
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
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
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
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