[Python-3000] A new member for contextlib?

Zaur Shibzoukhov szport at gmail.com
Fri Apr 4 20:12:17 CEST 2008


Benjamin Peterson:
> I don't really see how this is better/easier than:
> class AAA:
>     def get_x(): pass
>     def set_x(): pass
>     x = property(get_x, set_x, None, "The x property")

Perhaps it's better because :)

@classmethod
def func(self): pass

is better than

def func(self): pass
func = classmethod(func)


Christian Heimes:
> Python 2.6 and 3.0 already have a new way to modify properties:
>
> class C(object):
>     @property
>     def x(self): return self._x
>     @x.setter
>     def x(self, value): self._x = value
>     @x.deleter
>     def x(self): del self._x

Certainly! It don't intent to replace this way of defining/modifining
properties. First, it is an example of "with" statement application.
Second, suggested approach allow to write your example in the
following way:

class C(object):
    with property as x:
        def get(self): return self._x
        def set(self, value): self._x = value
        def del(self): del self._x

IMHO it's quite readable too because of additional identation.


More information about the Python-3000 mailing list