Jennie wrote: > 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__', ...]
In Python 3 the way to specify the metaclass has changed: >>> class FooType(type): ... def __dir__(self): return ["python"] ... >>> class Foo(metaclass=FooType): ... pass ... >>> dir(Foo) ['python'] -- http://mail.python.org/mailman/listinfo/python-list