[Tutor] self self self

Remco Gerlich scarblac@pino.selwerd.nl
Tue, 18 Jul 2000 00:41:45 +0200


On Mon, Jul 17, 2000 at 12:13:32PM -0700, Isaac wrote:
> in java classes, the 'self' namespace is automatically
> available.  instance methods automatically include the self ('this' in
> java) as the first argument, so we don't have to worry about it.  And
> the same goes for accessing instance vars and methods.
> 
> Is there any good and reasonable way to circumvent having to include
> 'self.' in front of every instance attribute reference in python?  Or if
> not, what's the likelihood of the language adding an automatic search in
> the class' (object's) namespace in the future?

Well, you could use 's.' instead of 'self.'...

I don't think it will go. It makes code clear (you can tell the difference
between instance and local variables immediately). How would Python tell the
difference between the local namespace, the global namespace and the
instance's namespace? In Java it's necessary to declare variables and that
info can be used, but as Python is so dynamic, I don't see that happen.

It would be irritating if every loop counter or so you used in a method
would be added to the instance...

-- 
Remco Gerlich,  scarblac@pino.selwerd.nl