"Martin v. Löwis" <martin@v.loewis.de> wrote in news:3E312900.90100@v.loewis.de: > Duncan Booth wrote: >> How about this: >> >> class A(object): >> >> def foo(self, foo) [property.set]: >> "Setter for property 'foo'." >> self.__foo = foo >> >> def foo(self) [property.get]: >> "Getter for property 'foo'." >> return self.__foo > > This is beautiful, but it does not work: when defining the getter, you > need both the old property, and the new function object. Gah!, I must be asleep today. Something like this might work (although it is getting a bit messy): def set(fn): get, delete, doc = None, None, fn.__doc__ namespace = inspect.getcurrentframe().f_back.f_locals oldfn = namespace.get(fn.__name__) if isinstance(oldfn, property): get, delete, doc = oldfn.fget, oldfn.fdel, oldfn.__doc__ return property(get, fn, delete, doc) -- Duncan Booth duncan@rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4