[Tutor] problem with class - get message that self is not defined

Bob Gailer bgailer at alum.rpi.edu
Tue May 23 21:59:04 CEST 2006


Alan Gauld wrote:
>> When I try to use the class listed below, I get the statement that 
>> self
>> is not defined.
>>
>> test=TriggerMessage(data)
>> var = test.decode(self.qname)
>>
>> I would have thought that self would have carried forward when I 
>> grabbed
>> an instance of TriggerMessage.
>>     
>
> self is a special varianble 
"special variable" could be confusing. Python has no "special 
variables". "self" is used by convention. One could use "this" as an 
alternative, or any other variable. When defining a method in a class 
one writes def abc(self, a,b,c) OR def abc(this, a,b,c). Then one refers 
to "self" or "this" within the method to refer to the instance calling 
the method.

-- 
Bob Gailer
510-978-4454

Broadband Phone Service for local and long distance $19.95/mo plus 1 mo Free <http://click.linksynergy.com/fs-bin/click?id=NXXZaiArugE&offerid=86109.10000010&type=3&subid=0>



More information about the Tutor mailing list