property() type that only protects set?
Neal Norwitz
neal at metaslash.com
Tue Apr 9 17:06:43 EDT 2002
Brad Clements wrote:
>
> Anyone have an implementation of property() that doesn't require a getter,
> only a setter (and optional del)
>
> I only need to protect set operations, and want to allow get to go straight
> to __dict__
>
> (or object when I'm using slots)
>From the docstring:
>>> print property.__doc__
property(fget=None, fset=None, fdel=None, doc=None) -> property attribute
fget is a function to be used for getting an attribute value, and likewise
fset is a function for setting, and fdel a function for del'ing, an
attribute. Typical use is to define a managed attribute x:
class C(object):
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.")
----------------------------------------------------------------------------
so use:
x = property(fset=setx)
Neal
More information about the Python-list
mailing list