Class probkem - getting msg that self not defined

Dennis Benzinger Dennis.Benzinger at gmx.net
Mon May 22 21:21:13 CEST 2006


wes weston schrieb:
> Andrew Robert wrote:
> 
>> wes weston wrote:
>>
>>> Andrew Robert wrote:
>>>
>>>> Hi Everyone,
>>>>
>>>> I am having a problem with a class and hope you can help.
>>>>
>>>> When I try to use the class listed below, I get the statement that self
>>>> is not defined.
>>>>        test=TriggerMessage(data)
>>>
>>> self is not known here; only inside the class.
>>>
>>>> var = test.decode(self.qname)
>>>>
>> <snip>
>>
>> I guess I was barking up the wrong tree on that one.
>>
>> How would I go about getting the required values out of the class?
>>
>> Return self?
> 
> 
> You can refer to the variables inside the class as test.version;
> for example - as they are not protected. Or, you could add access
> methods in the class like def GetVersion(self): return self.version
> If you want to protect version, call it self.__version which mangles
> the name from outside.
> wes

Or use the property function to define properties 
<http://docs.python.org/lib/built-in-funcs.html>.

Dennis



More information about the Python-list mailing list