accessing dictionary keys
Carsten Haese
carsten.haese at gmail.com
Thu Oct 1 16:34:49 EDT 2009
Andreas Balogh wrote:
> Hello,
>
> when building a list of points like
>
> points = [ ]
> points.append((1, 2))
> points.append((2, 3))
>
> point = points[0]
>
> eventually I'd like to access the tuple contents in a more descriptive
> way, for example:
>
> print point.x, point.y
I'm not sure exactly what you're asking, but maybe the following code
will serve as a zeroth iteration toward the solution you seek:
py> class Point(object):
... def __init__(self, x, y):
... self.x = x
... self.y = y
...
py> points = []
py> points.append(Point(1, 2))
py> points.append(Point(2, 3))
py>
py> point = points[0]
py> print point.x, point.y
1 2
HTH,
--
Carsten Haese
http://informixdb.sourceforge.net
More information about the Python-list
mailing list