Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/306.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 最后一个坐标值返回零_Python_List - Fatal编程技术网

Python 最后一个坐标值返回零

Python 最后一个坐标值返回零,python,list,Python,List,最后一个_坐标[]值在假定返回坐标[]的先前值时返回零。它通过一个摄像头实时读取数据,该摄像头告诉被检测物体的坐标。我之所以要实现上一个坐标值,是为了比较以前的坐标值和新的坐标值,以区分它们并执行操作。我该如何解决这个问题 import socket import os,sys import time from threading import Thread HOST = '59.191.193.67' PORT = 5555 coor

最后一个_坐标[]值在假定返回坐标[]的先前值时返回零。它通过一个摄像头实时读取数据,该摄像头告诉被检测物体的坐标。我之所以要实现上一个坐标值,是为了比较以前的坐标值和新的坐标值,以区分它们并执行操作。我该如何解决这个问题

    import socket
    import os,sys
    import time
    from threading import Thread

    HOST = '59.191.193.67'
    PORT = 5555

    coordinates = []

    def connect():   
        globals()['client_socket'] = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        client_socket.connect((HOST,PORT))

    def update_coordinates():
        screen_width = 0
        screen_height = 0
        global last_coordinates
        last_coordinates = [0 for _ in range(19)]
        while True:
            try:
                client_socket.send("loc\n")
                data = client_socket.recv(8192)
            except:
                connect();
                continue;

            globals()['coordinates'] = data.split()
            if(not(coordinates[-1] == "eom" and coordinates[0] == "start")):
                continue

            if (screen_width != int(coordinates[2])):
                    screen_width = int(coordinates[2])
                    screen_height = int(coordinates[3])
                    return

            if (coordinates != last_coordinates):
                 return last_coordinates[16:19]
            last_coordinates = coordinates[:]



Thread(target=update_coordinates).start()

太多的代码。删掉与主题无关的内容。@defuz我应该删掉什么?介意编辑一下吗?我不太明白实际的问题是什么。代码太难理解了。提出确切的问题。什么不起作用?有什么不喜欢的?如果
更新坐标()
格式正确,则
while
之后的
If
将永远不会执行,因为
while
仅通过代码中的
返回退出。如果(屏幕宽度!=int(坐标[2]):
,则在
之后至少还有一个编辑错误。
。defuz评论的补充:删除所有
*robot*
函数,您不使用它们。也不需要
Thread()
,只需移除即可。halex评论的补充:您的缩进严重混乱:例如,
if
下面的行(在
while
循环末尾的
返回之前)没有缩进(下一行缩进两次)。