How to see the __name__ attribute of a class by using dir()
Jennie
nameDOTportua at gmail.com
Sat Oct 20 04:05:41 EDT 2012
The dir() built-in does not show the __name__ attribute of a class:
>>> '__name__' in Foo.__dict__
False
>>> Foo.__name__
'Foo'
I implementd my custom __dir__, but the dir() built-in do not want to
call it:
>>> class Foo:
... @classmethod
... def __dir__(cls):
... return ['python']
...
>>> Foo.__dir__()
['python']
>>> dir(Foo)
['__class__', '__delattr__', '__dict__', ...]
Can someone tell me where is the problem? Thanks a lot in advance
--
Jennie
More information about the Python-list
mailing list