Le Mardi 20 Juin 2006 18:36, Barry Kelly a écrit : > Yet when I try this with the 'type' type, it doesn't work: > > ---8<--- > > >>> x.__class__.__class__ > > <type 'type'> > > >>> x.__class__.__getattribute__('__class__') > you're looking for getattr :
In [11]: getattr(object, '__class__') Out[12]: <type 'type'> In [13]: getattr(str, 'translate') Out[13]: <method 'translate' of 'str' objects> > Traceback (most recent call last): > File "<stdin>", line 1, in ? > TypeError: descriptor '__getattribute__' requires a 'int' object but > received a 'str' > --->8--- > > Why is this? __getattribute__ is the descriptor interface, that means... humm see the doc i'm not enough skilled in english to explain in few words... but in python : In [27]: 'aaa'.replace('a', 'z') Out[27]: 'zzz' is exactly the same as : In [25]: str.__getattribute__('aaa', 'replace')('a', 'z') Out[25]: 'zzz' or even : In [26]: object.__getattribute__('aaa', 'replace')('a', 'z') Out[26]: 'zzz' -- _____________ Maric Michaud _____________ Aristote - www.aristote.info 3 place des tapis 69004 Lyon Tel: +33 426 880 097 -- http://mail.python.org/mailman/listinfo/python-list