Setting a Global Default for class construction?

Lao Coon laocoon at eudoramail.com
Fri Jan 31 17:40:52 EST 2003


Lao Coon <laocoon at eudoramail.com> wrote in news:Xns9314F01258E9CLaocoon@
62.153.159.134:

> Josh English <english at spiritone.com> wrote in 
> news:b1erj009ok at enews3.newsguy.com:
> 
>> Here is the code that I am struggling with in a Python module:
>> 
>> _Thing = "it"
>> 
>> def SetThing(s):
>>      global _Thing
>>      _Thing = str(s)
>> 
>> class NewThing:
>>      def __init__(self,thing=_Thing):
>>           self.Thing = _Thing
> 
> Here you're always setting self.Thing to "it"
> you want "self.Thing = thing"..

Hmm that's wrong of course! I misunderstood sorry.

add a
global _Thing in your definition of __init__ and you should be fine...

Lao




More information about the Python-list mailing list