C# style properties in python
- by 3D-Grabber
I am looking for a way to define properties in Python similar to C#, with nested get/set definitions.
This is how far I got:
#### definition ####
def Prop(fcn):
f = fcn()
return property(f['get'], f['set'])
#### test ####
class Example(object):
@Prop
def myattr():
def get(self):
return self._value
def set(self, value):
self._value = value
return locals() # <- how to get rid of this?
e = Example()
e.myattr = 'somevalue'
print e.myattr
The problem with this is, that it still needs the definition to 'return locals()'.
Is there a way to get rid of it?
Maybe with a nested decorator?