[Python-Dev] Extended Function syntax (original) (raw)
Duncan Booth duncan@rcp.co.uk
Fri, 24 Jan 2003 11:42:55 +0000
- Previous message: [Python-Dev] Extended Function syntax
- Next message: [Python-Dev] Extended Function syntax
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
John Williams <jrw@pobox.com> wrote in news:3E300A13.6020303@pobox.com:
Compared to the other proposal going around (which I'll call Guido's, since he brought it up), the really big advantage of my proposal is that you can use it to do something like adding a property to a class implicitly by defining its getter and setter methods:
class A(object): def get foo(self): "Getter for property 'foo'." _return self.foo def set foo(self, foo): "Setter for property 'foo'." _self.foo = foo At this stage I'd much rather see Guido's proposal implemented, unless someone comes up with a truly ingenious way to combine the advantages of both.
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
Then add static methods to property that look something like this:
def set(fn): if isinstance(fn, property): return property(fn.fget, fn, fn.fdel, fn.doc) else: return property(fset=fn)
def get(fn): ... def delete(fn): ...
-- 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?
- Previous message: [Python-Dev] Extended Function syntax
- Next message: [Python-Dev] Extended Function syntax
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]