[Tutor] Inner Class access to outer class attributes?

Kent Johnson kent37 at tds.net
Thu Mar 23 23:18:15 CET 2006


stv wrote:
> Hmmm, so every Sublocation object has a copy of the grouplocation
> data? 

No, as Danny explained it is a reference to the data, not a copy.

> 
> Is there a better way to skin this cat? Or am I stuck with a) the
> non-inner class design & it's ugly indexes
> 
> for sub in group.sublocations:
> if sub[1] == 'foo':
>  print group.group_location, sub[0]
> 
> or b) data duplication & possible un-synching.

There is an intermediate solution as well. You could use a sublocations 
class with attributes but no reference to its parent. Then the above 
would be

for sub in group.sublocations:
if sub.action == 'foo':
  print group.group_location, sub.sublocation

Kent




More information about the Tutor mailing list