Compromise solution: Instead of a class, make Coord3D a namedtuple and return that :-)
Usage:
Coord3D = namedtuple('Coord3D', 'x y z')
def getCoordinate(index):
# do stuff, creating variables x, y, z
return Coord3D(x, y, z)
The return value can be used exactly as a tuple, and has the same speed and memory properties, so you don't lose any genericity. But you can also access its values by name: if c
is the result of getCoordinate(index)
, then you can work with c.x
, c.y
, etc, for increased readibility.
(obviously this is a bit less useful if your Coord3D class needs other functionality too)
[if you're not on python2.6, you can get namedtuples from the cookbook recipe]