PEP318: property as decoration

Gerrit Holl gerrit at
Wed Jun 11 20:40:25 CEST 2003

Sean Ross wrote:
>         def foo():
>                 def fget(self):
>                         return self._foo
>                 def fset(self, value):
>                         self._foo = value
>                 def fdel(self):
>                         del self._foo
>                 fdoc = "foo"
>                 return fget, fset, fdel, fdoc

Make that: "return fget, fset, fdel, __doc__".

>         foo = property(*foo())
>         def bar():
>                 "a readonly property"
>                 def fget(self):
>                         return self._bar
>                 return fget,     # the trailing comma is required here

And that: "return fget, None, None, bar.__doc__"

>         bar = property(*bar())

> Anyway...I found this interesting, so I thought someone else might enjoy it
> as well.

Yes, sure. If the class-solution wouldn't be such an abuse, I would use
that but it goes against the grain with me. Maybe I will start using
this way...


149. If this woman does not wish to remain in her husband's house, then
he shall compensate her for the dowry that she brought with her from her
father's house, and she may go.
        -- 1780 BC, Hammurabi, Code of Law
Asperger Syndroom - een persoonlijke benadering:
Het zijn tijden om je zelf met politiek te bemoeien:

More information about the Python-list mailing list