如何修复此错误,pos_coordinates 包含一个值列表,而 updatePos_coordinates 是先前复制到 updatePos_coordinates 列表中的 pos_coordiantes 值。我想找出对象和索引值 8、9、12 和 13 之间的差异。但我不断收到此错误。我该如何解决这个问题
screen_width = 0
screen_height = 0
updatePos_coordinates = []
while True:
client_socket.send("loc\n")
data = client_socket.recv(8192)
pos_coordinates = data.split()
if(not(pos_coordinates[-1] == "eom" and pos_coordinates[0] == "start")):
continue
if (screen_width != int(pos_coordinates[2])):
screen_width = int(pos_coordinates[2])
screen_height = int(pos_coordinates[3])
if (pos_coordinates != updatePos_coordinates):
if(cmp(pos_coordinates[8:10], updatePos_coordinates[8:10]) == 0):
both.brake()
print "Ball is in the same location.."
if((pos_coordinates[8] - updatePos_coordinates[8] > 5) or (pos_coordinates[8] - updatePos_coordinates[8] < -5) or (pos_coordinates[9] - updatePos_coordinates[9] > 5) or (pos_coordinates[9] - updatePos_coordinates[9] < -5)):
activateRobot(pos_coordinates)
else:
both.brake()
print "Ball is in the same location.."
updatePos_coordinates = pos_coordinates[:]
time.sleep(3)
print '...........'
我不断得到这个:
Traceback (most recent call last):
File "test.py", line 155, in <module>
if((pos_coordinates[8] - updatePos_coordinates[8] > 5) or (pos_coordinates[8] - updatePos_coordinates[8] < -5) or (pos_coordinates[9] - updatePos_coordinates[9] > 5) or (pos_coordinates[9] - updatePos_coordinates[9] < -5)):
IndexError: list index out of range