On 10/20/2012 11:43 AM, Peter Otten wrote:
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']
Thanks! :)
--
Jennie
--
http://mail.python.org/
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']
>>
>>
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 doe
Jennie wrote:
> 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
> ... d