newbie: self.member syntax seems /really/ annoying

Diez B. Roggisch deets at nospam.web.de
Wed Sep 12 06:34:59 EDT 2007


> 
>     with self:
>       .a_dot = -.k(.a-.u)
> 
> It's premature to make language suggestions as I am new to the
> language, but I would have though that making a 'with self' explicit
> in all methods would have been neat, so I could just write
>       .a_dot = -.k(.a-.u)
> which would still avoid confusion with local function variables, since
> '.a' is different from 'a'.
> 
> Please help if I am missing something -- this looks like a great
> language but I am going to mad trying to read numerical code full of
> 'self.'s breaking up the equations.

This is a FAQ - and the short answer is: no, you don't miss anything, and
it's not going change. If you want, you can shorten the expressions like
this:

s = self
s.a * s.b

Or choose any other valid name, e.g. the underscore.

Another (yet rather ugly) alternative would be to push the names into the
global namespace. But that could of course create major mayhem! So take
this with a huge grain of salt:

globals().update(self.__dict__)

a * b

Diez



More information about the Python-list mailing list