Tuesday, May 6, 2008

Clean Python getters and setters

From Diez Roggish answering a question from Daniel Fetchinson at the end of November:

class Foo(object):

@apply
def x( ):
def fget(self):
return self.__x
def fset(self, value):
self.__x = value
return property(**locals( ))

Clean getters and setters ... with decorator magic. The original thread is here.

No comments: