Drilling down in a dict with "complex" objects
Sean DiZazzo
half.italian at gmail.com
Tue May 25 01:17:46 EDT 2010
On May 24, 9:34 pm, Six <john.d.perk... at gmail.com> wrote:
> I am trying to access an objects sub-object attributes. I can boil the
> code I am working with down to this problem section:
> (snip)
> class Pt:
> x = None
> y = None
> def __init__(self, x, y):
> self.x, self.y = x, y
> pass
>
> class Pts:
> curr_point = None
> next_point = None
> def __init__(self, n, m):
> self.next_point = Pt(n, m)
> def update(self, point):
> self.curr_point = self.next_point
> self.next_point = point
>
> class PtManage:
> points = {}
> def __init__(self):
> pass
>
> point = Pts(3,5)
> pman = PtManage()
> pman.points["odds"] = point
> print dir(pman)
>
> print pman["odds"].next_point.x
>
> (snip)
>
> It's this last line that doesn't work. What am I doing wrong? Is this
> a failure of the design or am I missing something obvious? How do I
> get down and see that "Pt" classes x attribute within the PtManage
> dict?
Don't you mean?
pman.points["odds"].next_point.x
More information about the Python-list
mailing list