A better self

Greg Ewing see_reply_address at something.invalid
Mon Jul 22 21:29:37 EDT 2002


Michael Chermside wrote:

>>>
>     def pretendFormula(x,y,z,t):
>         return sin(t) * x**y + sqrt(z)
> 
>     def MyClass:
>         def pretend(self):
>             return pretendFormula(self.x, self.y, self.z, self.t)


You could do slightly better than that, if you
don't want to be bothered passing in the args
one at a time (untested):

   def pretendFormula(x, y, z, t, **_):
     return sin(t) * x**y + sqrt(z)

   def MyClass:
     def pretend(self):
       return pretendFormula(**self.__dict__)

-- 
Greg Ewing, Computer Science Dept,
University of Canterbury,	
Christchurch, New Zealand
http://www.cosc.canterbury.ac.nz/~greg




More information about the Python-list mailing list