use of "self", was "No Do while/repeat until looping construct in python?"
wsonna at attglobal.net
Tue Mar 18 09:17:23 CET 2003
On Mon, 17 Mar 2003 10:09:53 +1100, Delaney, Timothy C (Timothy) wrote:
>> From: William Sonna [mailto:wsonna at attglobal.net]
>> There actually is another alternative - mass qualification.
>> There is/(was)? a scripting lanuage that uses/(d)? the following:
>> ::method tag
>> expose name address salutation
>> separator = 'at:'
>> return salutation name separator address
> Ah - the common "with" suggestion.
I don't believe so.
> The major problem with "with"-type suggestions is that they only work at
> one level. As soon as you get to multi-level qualifications you
> immeditely lose the ability to know what name belongs where.
> Indeed, in Python you can lose that ability immediately.
> class Klass:
> def func (self, anotherObject):
> a = 1
> with self:
> b = 1
> with anotherObject:
> a = 2
> c = b
> Okay - in the last line, what namespace(s) are `a`, `b` and `c` using?
Whatever the language defines it to be. The usual suspects: first "with";
nearest "with"; namespace of same object; etc.
What I think you've missed, however, is that the closest Python
approximation to the expose statement is actually:
def func(self, anotherObject):
a,b,c = self.a, self.b, self.c
Which I think you'll agree IS unambiguous.
The reason expose syntax works is because the unnamed scripting language
enforces/maintains a special relationship between an instance and its
Python does not.
More information about the Python-list