Python property does not set

properties, python

Solution

The documentation for `property()` states:

Return a property attribute for new-style classes (classes that derive from object).

Your class is not a new-style class (you didn't inherit from object). Change the class declaration to:

class A(object):
    ...

and it should work as intended.

Problem

Here is the code: ``` 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 ``` Above produces the following output: ``` {'doc': 'As name', 'fset': <function fset at 0x10b68e578>, 'fdel': None, 'fget': <function fget at 0x10b68ec08>} John John Bob John ``` The code is taken from here. Question: what's wrong? It should be something simple but I can't find it. Note: I need property for complex getting/setting, not simply hiding the attribute. Thanks in advance.

Original source