How to see the __name__ attribute of a class by using dir()

Jennie nameDOTportua at gmail.com
Sat Oct 20 04:59:36 EDT 2012


On 10/20/2012 10:24 AM, Peter Otten wrote:

> So if you want to customise dir(Foo) you have to modify the metaclass:
>
>>>> >>>class Foo:
> ...     class __metaclass__(type):
> ...             def __dir__(self): return ["python"]
> ...
>>>> >>>dir(Foo)
> ['python']
>
>

Hi Peter, thanks for your answer, but it does not work (Python 3.3):

 >>> class Foo:
...     class __metaclass__(type):
...         def __dir__(self): return ["python"]
...
 >>> dir(Foo)
['__class__', '__delattr__', '__dict__', '__dir__', ...]

Regards,
-- 
Jennie



More information about the Python-list mailing list