Another try at Python's selfishness
Paul McGuire
ptmcg at austin.rr._bogus_.com
Thu Feb 2 18:49:34 EST 2006
<n.estner at gmx.de> wrote in message
news:1138918102.863033.298700 at o13g2000cwo.googlegroups.com...
> Having read previous discussions on python-dev I think I'm not the only
> Python programmer who doesn't particularly like python's "self"
> parameter:
>
How about this decorator-based approach (still need to pick *some* name for
self, I picked "__").
-- Paul
def memberFunction(f):
def func(self,*args,**kwargs):
globals()["__"] = self
return f(*args,**kwargs)
func.__name__ = f.__name__
func.__doc__ = f.__doc__
func.__dict__.update(f.__dict__)
return func
class Test:
@memberFunction
def __init__(x,y):
__.x = x
__.y = y
@memberFunction
def mult():
"Multiply the two member vars"
return __.x * __.y
t = Test(5,4)
print t.mult()
print dir(t)
print t.mult.__doc__
More information about the Python-list
mailing list