Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!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; 'subject:Python': 0.06; 'attribute': 0.07; 'compiler': 0.07; 'nested': 0.07; 'wednesday,': 0.07; 'output,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'python': 0.11; '24,': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'wrote:': 0.18; '>>>': 0.22; 'print': 0.22; 'header:User- Agent:1': 0.23; 'developers': 0.25; 'pass': 0.26; 'defined': 0.27; 'skip:_ 20': 0.27; 'header:X-Complaints-To:1': 0.27; 'class': 0.32; 'skip:_ 10': 0.34; 'subject:the': 0.34; 'agree': 0.35; 'definition': 0.35; 'subject:?': 0.36; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'enough': 0.39; 'received:org': 0.40; 'expectations': 0.74; "'foo'": 0.84; '2013': 0.98 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Peter Otten <__peter__@web.de> Subject: Re: What is the reason for defining classes within classes in Python? Date: Wed, 24 Apr 2013 14:00:55 +0200 Organization: None References: <4e46cc04-248e-4594-a24a-b272648a5e66@googlegroups.com> <2cec7512-997e-4f1f-9580-592495d449df@ys5g2000pbc.googlegroups.com> <7143de25-61a1-4eaf-abd1-2eab03c913f8@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Gmane-NNTP-Posting-Host: p5084bfc0.dip0.t-ipconnect.de 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: 48 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1366804839 news.xs4all.nl 16002 [2001:888:2000:d::a6]:52415 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:44263 vasudevram wrote: > On Wednesday, April 24, 2013 6:20:36 AM UTC+5:30, alex23 wrote: >> >> A nested class definition will be defined as an attribute of the class >> >> its defined within: >> >> >> >> >>> class Outer(object): >> >> ... foo = 'FOO' >> >> ... class Inner(object): >> >> ... bar = 'BAR' >> >> ... >> >> >>> Outer.Inner > Just one other doubt: > >> >>> Outer.Inner >> >> >> > > In the above output, I would have thought Python would print > __main__.Outer.Inner or Outer.Inner instead of __main__.Inner, since Inner > is an attribute of Outer? The Python developers seem to agree with you and have made the compiler smart enough to accomodate your expectations in Python 3.3: $ cat tmp.py class Outer: class Inner: pass print(Outer.Inner) $ python3.2 tmp.py $ python3.3 tmp.py