这是代码:
def Property(func):
return property(**func())
class A:
def __init__(self, name):
self._name = name
@Property
def name():
doc = A s name
def fget(self):
return self._name
def fset(self, val):
self._name = val
fdel = None
print locals()
return locals()
a = A( John )
print a.name
print a._name
a.name = Bob
print a.name
print a._name
以上产出如下:
{ doc : As name , fset : <function fset at 0x10b68e578>, fdel : None, fget : <function fget at 0x10b68ec08>}
John
John
Bob
John