Here is the code:
def Property(func): return property(**func()) class A: def __init__(self, name): self._name = name @Property def name(): doc = 'A' 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
The following output is output above:
{'doc': 'As name', 'fset': <function fset at 0x10b68e578>, 'fdel': None, 'fget': <function fget at 0x10b68ec08>} John John Bob John
The code is taken here .
Question: what happened? It should be something simple, but I cannot find it.
Note. I need a property for complex getting / setting, and not just hiding an attribute.
Thanks in advance.
source share