Enhanced property decorator

Benjamin musiccomposition at gmail.com
Mon Aug 25 21:52:24 EDT 2008


On Aug 25, 8:45 pm, Daniel <miller... at gmail.com> wrote:
> I've often been frustrated by the inability of the built-in property
> descriptor to handle anything other than a read-only property when
> used as a decorator. Furthermore, read/write/delete properties take
> their doc-string and property definition at a non-intuitive and
> awkward place (after the getter/setter/delter functions). The
> following are three possible solutions to this problem (inspired by
> messagehttp://groups.google.com/group/comp.lang.python/msg/9a56da7ca8ceb7c7).
> I don't like the solution in that thread because it uses apply() which
> will go away in Python 3.

I didn't read the rest of the thread, but I think Python 2.6 may have
want you want:

class A(object):

    @property
    def my_prop(): return self._prop

    @my_prop.setter
    def my_prop(prop): self._prop = prop

    @my_prop.deleter
    def my_prop(): del self._prop



More information about the Python-list mailing list