Setting a Global Default for class construction?

Josh English english at spiritone.com
Fri Jan 31 16:58:54 EST 2003


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

I thought that this would work if I called:

 >>>SetThing('hallo')
 >>>a = NewThing()
 >>>a.Thing
'it'

I would expect a.Thing to return 'hallo', not 'it'. Is this possible to 
do in Python?

Josh English





More information about the Python-list mailing list