Do I always have to write "self." ?
scarblac-spamtrap at pino.selwerd.nl
Thu Apr 27 17:28:42 EDT 2000
Louis M. Pecora wrote in comp.lang.python:
> I am two weeks plus into learning Python and have started on a first
> real project. Amazing language. BUT, now that I've gotten going with
> classes, I'm finding I hate seeing all those "self." prefixes on the
> class variables. Python is generally very clean, but the classes I
> write use a lot of "per-instance" variables, hence seem to require
> self. As a result the expressions can become cluttered and harder to
> read than C++ in this particular case -- imagine that! Is there any
> relief here? Any (simple) way around writing that self. every time?
No. However, this seems to make code *more* readable. In fact, many C++
programmers use 'this.x' for all their instance variables, to be able to
see at a glance which are just local variables of the function and which are
instance variables. It's just more work to write, but that doesn't matter
Python needs it to know which vars are instance variables, and which are
Funny how people say that every aspect of Python they don't like make the
language less "clean". It is extremely consistent though.
You *can* use another word for 'self' though, 's' or 'me' or something. But
it makes your code harder to read, of course...
Remco Gerlich, scarblac at pino.selwerd.nl
Hi! I'm a .sig virus! Join the fun and copy me into yours!
More information about the Python-list