Path: csiph.com!usenet.pasdenom.info!aioe.org!.POSTED!not-for-mail From: Jennie Newsgroups: comp.lang.python Subject: Re: How to see the __name__ attribute of a class by using dir() Date: Sat, 20 Oct 2012 10:59:36 +0200 Organization: Aioe.org NNTP Server Lines: 25 Message-ID: <508267F8.5030302@gmail.com> References: NNTP-Posting-Host: Hjw0bnoJjUJNtffijAdupA.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (X11; Linux i686; rv:16.0) Gecko/20121011 Thunderbird/16.0.1 X-Notice: Filtered by postfilter v. 0.8.2 Xref: csiph.com comp.lang.python:31802 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