override a property

Bengt Richter bokr at oz.net
Mon Oct 17 19:31:56 EDT 2005


On 17 Oct 2005 11:13:32 -0700, "SPE - Stani's Python Editor" <spe.stani.be at gmail.com> wrote:

>No, you can just do it on the fly. You can even create properties
>(attributes) on the fly.
>
>class Dummy:
>   property = True
>
>d = Dummy()
>d.property = False
>d.new = True
>
a simple attribute is not a property in the sense Robin meant it,
and a "data property" is even more specific. See

    http://docs.python.org/ref/descriptor-invocation.html

also

 >>> help(property)
 Help on class property in module __builtin__:

 class property(object)
  |  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.")
  |


Regards,
Bengt Richter



More information about the Python-list mailing list