Getting rid of "self."

Jeremy Bowers jerf at
Fri Jan 7 23:48:43 EST 2005

On Fri, 07 Jan 2005 14:39:09 +0100, BJörn Lindqvist wrote:
> It works! exec(magic()) does the needed hi = self.hi.

No it doesn't. Try "hi = 'newValue'" and see what happens.

So the next step is to write an "unmagic" function. So now how do you add
instance variables?

There is no way to avoid "self" *and* not pre-declare variables in some
fashion as belonging to the instance (as declarations, as sigils, what
have you). Given that Python is not, will not, and should not do the
latter, I submit that "self" is, at least for you, the lesser of two
evils. (I don't consider it evil at all, so it isn't such for me; were I
programming in C++ routinely now I'd prefix "this" and dispense with that
ugly "m_" garbage. (One of the things I ***hate*** about C++ culture is
its acceptance of hideously ugly variable names, but now I'm two
parentheticals deep so I probably ought to stop.))

More information about the Python-list mailing list