X
xtian
Avner Ben said:The "property" call resembles both classmethod, staticmethod and
instancemethod, but cannot be eliminated using the new function
decorator syntax, because of its m:1 nature - one property binds
together a getter, a setter etc., where staticmethod etc. change the
status of one function in one way.
[snip]
Talking about properties, I like the C# way of defining them, which is
straightforward and readable. The property begins like a method, but has
no argument list and includes a getter function with no arguments and a
setter function with one argument. Adapted to Python, it would look
something like:
class hasProperty:
def __init__(self,aProperty='')
self.aProperty = aProperty
def AProperty:
def get(self):
return self.aProperty
def set(self,value):
self.aProperty = value
obj = hasProperty()
obj.AProperty = 'test'
print obj.AProperty
I'm not sure that this application of the new syntax is much worse
than what you've got... (it *is* a bit hacky in that it's calling the
function it's wrapping, but there you go).
return property(*f())
def __init__(self):
self._foo = 1
@property_
def foo():
def get(self):
print "get"
return self._foo
def set(self, val):
print "set"
self._foo = val
return get, set
getget
1
3
What do people think of something like this?
Cheers,
xtian