[Tutor] Inner Class access to outer class attributes?
Alan Gauld
alan.gauld at freenet.co.uk
Fri Mar 24 01:17:41 CET 2006
> Hmmm, so every Sublocation object has a copy of the grouplocation
> data? What happens if I come around & change something:
Recall that in Python variables are simply references to objects.
So every sublocation has a reference to the same groupLocation object
> Would I need to (forgive me here if I get some terms wrong) use a
> property (or a setter) & then loop over all the affected sublocations
No, just change the groupLocation and the change will show
up in every sublocation.
FWIW this is how virtually all GUI frameworks operate,
the top level window is passed as a parent to each widget.
> Is there a better way to skin this cat? Or am I stuck with a) the
> non-inner class design & it's ugly indexes
The problem appears to be that you need to read a bit more
about Pythons handling of variable names and objects. :-)
Alan G
Author of the learn to program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld
More information about the Tutor
mailing list