Immutability
Fredrik Lundh
fredrik at pythonware.com
Wed Jun 28 13:28:06 EDT 2006
Nick Maclaren wrote:
> I wasn't expecting EITHER to be turned INTO a property - I was expecting
> both methods to be the same, but one would have non-default properties
> attached to it.
> |> that's what the documentation
> |> says, and that's what your code is doing.
>
> Er, no, it doesn't. What it says may well be COMPATIBLE with that, but
> it is compatible with a good many other interpretations, too. Until and
> unless you know what it means, you can't extract its meaning from its
> words.
well, I completely fail to see how the following is compatible with the
interpretation "attaches a non-default property, but doesn't do anything
else":
property([fget[, fset[, fdel[, doc]]]]) => descriptor
Returns a property attribute for new-style classes (classes that
derive from object).
fget is a function for getting an attribute value, likewise fset is a
function for setting, and fdel a function for deleting, an
attribute. Typical use is to define a managed attribute x:
class C(object):
def __init__(self): self.__x = None
def getx(self): return self.__x
def setx(self, value): self.__x = value
def delx(self): del self.__x
x = property(getx, setx, delx, "I'm the 'x' property.")
</F>
More information about the Python-list
mailing list