Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; '(python': 0.05; 'modify': 0.05; 'subject:How': 0.09; 'python': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:()': 0.09; 'subject:using': 0.09; 'def': 0.10; '...]': 0.16; 'metaclass': 0.16; 'received:80.91.229.3': 0.16; 'received:dip.t-dialin.net': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-dialin.net': 0.16; 'subject:class': 0.16; 'wrote:': 0.17; 'specify': 0.17; '>>>': 0.18; 'skip:_ 20': 0.22; 'pass': 0.25; 'header:User-Agent:1': 0.26; 'skip:[ 10': 0.26; 'am,': 0.27; 'header:X-Complaints-To:1': 0.28; 'skip:_ 10': 0.29; 'class': 0.29; "skip:' 10": 0.30; 'to:addr:python-list': 0.33; 'thanks': 0.34; 'received:org': 0.36; 'but': 0.36; 'does': 0.37; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'your': 0.60; 'otten': 0.84; 'peter,': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Peter Otten <__peter__@web.de> Subject: Re: How to see the __name__ attribute of a class by using dir() Date: Sat, 20 Oct 2012 11:43:25 +0200 Organization: None References: <508267F8.5030302@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Gmane-NNTP-Posting-Host: p50849431.dip.t-dialin.net User-Agent: KNode/4.7.3 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 36 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1350726214 news.xs4all.nl 6881 [2001:888:2000:d::a6]:33534 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:31805 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']