Thursday, July 21, 2005

Python Buzz Forum - property decorator

Python Buzz Forum - property decorator: "For some reason it never occurred to me that you could use property() as a decorator. Of course, if you want to use getters and setters you can't, but for the (fairly common) case when you have a function that you want to turn into a read-only attribute, it works great:

class Foo(object):
@property
def bar(self):
return

Huh. Seems obvious now."