newbie: self.member syntax seems /really/ annoying

Michele Simionato michele.simionato at gmail.com
Wed Sep 12 06:32:59 EDT 2007


On Sep 12, 12:21 pm, Charles Fox <charles.... at gmail.com> wrote:
> I've just started playing around with Python, as a possible
> replacement for a mix of C++, Matlab and Lisp.  The language looks
> lovely and clean with one huge exception:  I do a lot of numerical
> modeling, so I deal with objects (like neurons) 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)
> For large equations this is going to make my code seriously unreadable
> to the point of needing to switch back to Matlab -- and it seems to go
> against everything else about python's simplicity and elegance.  Am I
> missing something?  Is there something like a 'with' command that lets
> me set the scope, like
>
>     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.

You can always use aliases

a = self.a
u = self.u
...

or even s = self

or play games with dictionaries.


 Michele Simionato




More information about the Python-list mailing list