I had this Python 2.7 code which queries the movement limits from a device:
pan_low_limit = int(self.send_query("PN", 2))
pan_high_limit = int(self.send_query("PX", 2))
tilt_low_limit = int(self.send_query("TN", 2))
tilt_high_limit = int(self.send_query("TX", 2))
I thought I could write this nicer as:
limits = [(pan_low_limit, "PN"), (pan_high_limit, "PX"), (tilt_low_limit, "TN"), (tilt_high_limit, "TX")]
for v, c in limits:
v = int(self.send_query(c, 2))
print("Result from {}: {}".format(c, v))
print(limits)
print("tilt_low_limit: {}".format(tilt_low_limit))
Print statements are to find what's going on. When I run this, I get the following output (these four variables had been initialized with value 1 before this piece of code):
Result from PN: -27067
Result from PX: 27067
Result from TN: -27999
Result from TX: 9333
[(1, 'PN'), (1, 'PX'), (1, 'TN'), (1,'TX')]
tilt_low_limit: 1
PN: 1
I don't really get what's going on. It seems like the value of v in "v = int(self.send_query(c, 2))"
is what I'd expect, but at the next line, these variables have the old values again?