Classes in a class: how to access variables from one in another

alex23 wuwei23 at gmail.com
Tue Oct 19 02:28:26 EDT 2010


Steven D'Aprano <steve-REMOVE-T... at cybersource.com.au> wrote:
> Avoiding namespace pollution and information hiding are two good reasons
> for nesting classes.

Python already has a great mechanism for regulating namespaces:
modules & importing. Information hiding seems to go against the 'all
consenting adults' ethos as well.

> There's no need to expose the Node class, and no reason not to nest it.

Well, other than maybe code reuse, that seems a good reason to me.
Being able to modify the behaviour of someone else's class because
they _haven't_ nested secondary class functionality within it would be
a big plus too, even more so if the outer class instead takes a class
or factory as part of its constructor.



More information about the Python-list mailing list