Gabriel Genellina a écrit :
En Mon, 02 Feb 2009 19:51:11 -0200, Russ P. <russ.paie...@gmail.com> escribió:

Suppose a library developer (or a module developer on a large team)
uses leading underscores. Now suppose that, for whatever reason
(pressure from the users, perhaps), the library developer decides to
change a "private" attribute to public. Now all occurrences of the
identifier need to be changed. If an assignment to the previously
"private" attribute is missed, no warning will be issued (because
Python allows new attributes to be added anywhere, even completely
outside the class definition itself). And if the library is widely
used, the probability of such bugs occurring is very high.

So _foo becomes foo. Then:

class X(object):
    def get_foo(self): return self._foo
    def set_foo(self, value): self._foo = value
    foo = property(get_foo, set_foo)


FWIW, if there's no other need for the property, I'd do it the other way round : directly make foo a plain attribute, and add a _foo property whose accessors would raise a deprecation warning. Then there's no chance I miss a an assignement to _foo !-)

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to