How to use __get__()/__set__()
?
Like this if you have Python3. Descriptors in Python2.6 doesn't want works properly for me.
Python v2.6.6
>>> class Foo(object):
... def __get__(*args): print 'get'
... def __set__(*args): print 'set'
...
>>> class Bar:
... foobar = Foo()
...
>>> x = Bar()
>>> x.foobar
get
>>> x.foobar = 2
>>> x.foobar
2
Python v3.2.2
>>> class Foo(object):
... def __get__(*args): print('get')
... def __set__(*args): print('set')
...
>>> class Bar:
... foobar = Foo()
...
>>> x = Bar()
>>> x.foobar
get
>>> x.foobar = 2
set
>>> x.foobar
get