object.attribute vs. object.getAttribute()
Sean Ross
sross at connectmail.carleton.ca
Tue Sep 16 11:21:54 EDT 2003
Hi.
"Roy Smith" <roy at panix.com> wrote in message
news:roy-81B3E5.20291015092003 at reader2.panix.com...
[snip]
> 1) More typing (which implies more reading, which I think reduces the
> readability of the finished product).
> 2) Need to write (and test) all those silly little functions.
If you only intend to create simple properties[*], then the following recipe
may address issues 1) and 2) (except for the testing part):
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/157768
If you're going to create more complex properties, you may find this
recipe(idiom) of interest:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/205183
Hope that's useful,
Sean
[*] By "simple properties", I mean something like the following:
''' assume we're inside a class definition
and self.__foo has been initialized.
'''
def get_foo(self):
return self.__foo
def set_foo(self, value):
self.__foo = value
def del_foo(self):
del self.__foo
foo = property(fget=get_foo, fset=set_foo, fdel=del_foo, doc="foo")
More information about the Python-list
mailing list