Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #31799

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

From Jennie <nameDOTportua@gmail.com>
Newsgroups comp.lang.python
Subject How to see the __name__ attribute of a class by using dir()
Date 2012-10-20 10:05 +0200
Organization Aioe.org NNTP Server
Message-ID <k5tm0k$sph$1@speranza.aioe.org> (permalink)

Show all headers | View raw


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

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

How to see the __name__ attribute of a class by using dir() Jennie <nameDOTportua@gmail.com> - 2012-10-20 10:05 +0200
  Re: How to see the __name__ attribute of a class by using dir() Peter Otten <__peter__@web.de> - 2012-10-20 10:24 +0200
    Re: How to see the __name__ attribute of a class by using dir() Jennie <nameDOTportua@gmail.com> - 2012-10-20 10:59 +0200
      Re: How to see the __name__ attribute of a class by using dir() Peter Otten <__peter__@web.de> - 2012-10-20 11:43 +0200
        Re: How to see the __name__ attribute of a class by using dir() Jennie <nameDOTportua@gmail.com> - 2012-10-20 13:19 +0200
        Re: How to see the __name__ attribute of a class by using dir() Jennie <marco.buttu@gmail.com> - 2012-10-20 13:19 +0200
    Re: How to see the __name__ attribute of a class by using dir() Jennie <marco.buttu@gmail.com> - 2012-10-20 10:59 +0200

csiph-web