Local class variables? (mod_python problem)

Rory Campbell-Lange rory at campbell-lange.net
Thu Feb 22 05:31:51 EST 2007


We have a set of classes using static methods to retain reference
variables between operations. The problem is that the static variables
are not reset between operations when used through mod_python.

Although it is possible to reset the class variables between invocations
of the system, this has the potential of 'wiping out' these variables
when another user is using the system.

Is there a way of getting the equivalent of 'local class variables'? In
other words, a way of making 'print a' and 'print b' below provide the
same output?

Regards
Rory


class TryMe(object):
	x = 0
	y = 0

	def __init__(self):
		self.a = 0, self.b = 0

	@staticmethod
	def incrementer():
		TryMe.x += 1, TryMe.y += 1

	def addone (self):
		TryMe.x += 1, TryMe.y += 1
		self.a , += 1 self.b += 1

	def __repr__(self):
		return """
		TryMe.x = %d TryMe.y = %d self.a  = %d self.b  = %d
		""" % (TryMe.x, TryMe.y, self.a, self.b)

if __name__ == '__main__':

	a = TryMe()
	a.incrementer()
	a.addone()

	b = TryMe()
	b.incrementer()
	b.addone()

	print 'a:', a
	print 'b:', b


-- 
Rory Campbell-Lange 
<rory at campbell-lange.net>
<www.campbell-lange.net>



More information about the Python-list mailing list