Implementing class attribute access methods via pseudo-functi on o verloading.

Peter Otten __peter__ at web.de
Mon Oct 25 14:28:09 CEST 2004


Doran_Dermot at emc.com wrote:

> Maybe I should change that to read "I prefer:" and "However, the second
> version feels more natural to myself" ;-)

Note that properties don't interfere with your favourite accessor method
style:

>>> class T(object):
...     def title(self, value=None):
...             if value is None:
...                     print "reading title"
...             else:
...                     print "setting title to", value
...     title = property(title, title)
...
>>> T().title
reading title
>>> T().title = "new title"
setting title to new title

Peter




More information about the Python-list mailing list