[Tutor] Inner Class access to outer class attributes?
stv
stvsmth at gmail.com
Thu Mar 23 21:48:21 CET 2006
Hmmm, so every Sublocation object has a copy of the grouplocation
data? What happens if I come around & change something:
group.grouplocation = differentGroupLocationID
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
every time grouplocation is re-set? A-la de-normalized relational
database
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.
I'll take a).
On 3/23/06, Kent Johnson <kent37 at tds.net> wrote:
>
> If you want access to a GroupLocation instance, just pass it to the
> sublocation.
> >
> > class GroupLocation(list):
> >
> > class _Sublocation(object):
> > def __init__(self, sublocation, action):
> > self.sublocation = sublocation
> > self.action = action
>
> def __init__(self, grouplocation, sublocation, action):
> self.grouplocation = grouplocation
> self.sublocation = sublocation
> self.action = action
More information about the Tutor
mailing list