[Python-3000] A new member for contextlib?

Paul Moore p.f.moore at gmail.com
Fri Apr 4 20:40:40 CEST 2008


On 04/04/2008, Zaur Shibzoukhov <szport at gmail.com> wrote:
>  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.

It does look reasonably nice. But I'd suggest submitting it as a
recipe in the Python cookbook - it doesn't seem to me that it needs to
go in the core. I'm not entirely sure about it, as I don't think "with
property as x" reads right.

And you shouldn't call it "property" - that name is already builtin
(and it doesn't read right, see above). I can't think of a good name
that *does* read right in the context of "with ... as x", either.

Paul.


More information about the Python-3000 mailing list