[Python-ideas] immutable classes [was: pre-PEP: Default Argument Expressions]

Josiah Carlson jcarlson at uci.edu
Sun Feb 18 05:25:29 CET 2007


"Jim Jewett" <jimjjewett at gmail.com> wrote:
> >>> class Vector3D(tuple):
> ...         def __new__(self, x, y, z):
> ...             return super(Vector3D, self).__new__(self, (x, y, z))
> ...         x=property(lambda self: self[0])
> ...         y=property(lambda self: self[1])
> ...         z=property(lambda self: self[2])

That looks very much like Raymond Hettinger's named tuple recipe,
recently offered in python-dev:

    http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/500261

 - Josiah




More information about the Python-ideas mailing list