newbie: self.member syntax seems /really/ annoying

Ryan Ginstrom software at ginstrom.com
Wed Sep 12 07:16:16 EDT 2007


> On Behalf Of Charles Fox
> described mathematically in papers, by equations like
>     a_dot = -k(a-u)
> In other languages, this translates nicely into code, but as 
> far as I can tell, Python needs the ugly:
>     self.a_dot = -self.k(self.a-self.u)

In addition to the other advice you've received, if you don't need to
preserve state, you could avoid the "self" business by putting your
functions in a module instead of an object.

def k(a):
    return a**3

def dot(a, u)
    return -k(a-u)

Python modules are also objects, so they can serve in place of class
instances much of the time.

Regards,
Ryan Ginstrom




More information about the Python-list mailing list