baffling bug in this bit of code!

Daniel Jaeggi jaeggi at NOSPAMembl-heidelberg.de
Wed Jul 3 09:13:34 EDT 2002


Hi,

I'm reasonably new to python but I've used various other languages 
before. The bug in the following bit of code has got me banging my head 
as it should be trivial. If anyone can help, I'd be most grateful.

This snippet:

	# find maximum dimension
		max_x = 0
		max_y = 0
		for node in self.nodes.keys():
			# first x
			x = self.nodes[node].location.x
			print "for node",node,"x is",x
			print "max_x = ",max_x
			if (x > max_x):
				print "updating max_x"
				max_x = x
			# then y
			y = self.nodes[node].location.y
			print "for node",node,"y is",y
			print "max_y = ",y
			if (y > max_y):
				print "updating max_y"
				max_y = y
		# and print this out for now
		print "Max x dim is",max_x
		print "Max y dim is",max_y


produces this output:

for node COG0857 x is 269
max_x =  0
updating max_x
for node COG0857 y is 8
max_y =  0
updating max_y
for node COG0282 x is 312
max_x =  269
updating max_x
for node COG0282 y is 145
max_y =  8
for node COG0281 x is 30
max_x =  312
for node COG0281 y is 157
max_y =  8
for node COG0280 x is 170
max_x =  312
for node COG0280 y is 114
max_y =  8
Max x dim is 312
Max y dim is 8


Why does max_x get located and not max_y? Or, more specifically, why 
does max_y get correctly updated in the first iteration and not 
subsequently?!

Please save me from insanity!

Dan

_
"There must and shall be aspirin. If I do not have aspirin, I shall die."




More information about the Python-list mailing list