property syntax
Gabriel Genellina
gagsl-py2 at yahoo.com.ar
Thu Mar 8 05:20:36 EST 2007
En Thu, 08 Mar 2007 06:34:12 -0300, <bearophileHUGS at lycos.com> escribió:
> Probably you have already discussed this topic, but maybe you can
> stand touching it again briefly.
> Maybe properties aren't used so often to deserve a specific syntax,
> but I don't like their syntax much. Here I show some alternative
> solutions that work with the current Python, followed by a syntax
> idea, that may be better fit for Python 3.0 (but maybe changing its
> name it can be retrofitted into Python 2.6 too).
You miss this common way, that does not depend on metaclasses, nor base
classes, nor custom decorators... The only drawback is the "deprecated"
status of apply:
class Angle(object):
@apply
def rad():
doc = "The angle in radians"
def fget(self):
return self._rad
def fset(self, value):
self._rad = value
return property(**locals())
(Hmmm... I wonder what the 2to3 conversion tool is doing in this case?)
--
Gabriel Genellina
More information about the Python-list
mailing list