Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #44263
| From | Peter Otten <__peter__@web.de> |
|---|---|
| Subject | Re: What is the reason for defining classes within classes in Python? |
| Date | 2013-04-24 14:00 +0200 |
| Organization | None |
| References | <4e46cc04-248e-4594-a24a-b272648a5e66@googlegroups.com> <mailman.1001.1366755826.3114.python-list@python.org> <ebf43a37-c441-4a8a-9941-995377ae45e5@googlegroups.com> <2cec7512-997e-4f1f-9580-592495d449df@ys5g2000pbc.googlegroups.com> <7143de25-61a1-4eaf-abd1-2eab03c913f8@googlegroups.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1019.1366804839.3114.python-list@python.org> (permalink) |
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
>>
>> <class '__main__.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
<class '__main__.Inner'>
$ python3.3 tmp.py
<class '__main__.Outer.Inner'>
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
What is the reason for defining classes within classes in Python? vasudevram <vasudevram@gmail.com> - 2013-04-23 14:50 -0700
Re: What is the reason for defining classes within classes in Python? Ian Kelly <ian.g.kelly@gmail.com> - 2013-04-23 16:22 -0600
Re: What is the reason for defining classes within classes in Python? vasudevram <vasudevram@gmail.com> - 2013-04-23 16:13 -0700
Re: What is the reason for defining classes within classes in Python? alex23 <wuwei23@gmail.com> - 2013-04-23 17:50 -0700
Re: What is the reason for defining classes within classes in Python? vasudevram <vasudevram@gmail.com> - 2013-04-24 04:01 -0700
Re: What is the reason for defining classes within classes in Python? Peter Otten <__peter__@web.de> - 2013-04-24 14:00 +0200
Re: What is the reason for defining classes within classes in Python? vasudevram <vasudevram@gmail.com> - 2013-04-24 06:29 -0700
csiph-web