使用Python写入CSV文件并从Lua中读取

我需要连续每过“x”毫秒将一些数据写入CSV文件(CSV文件被重写)。我按照以下方式操作:

while(True):
    time.sleep(x)
    with open('path/to/csv_file_test', 'w') as f:
        # 创建csv读写器
        writer = csv.writer(f)
        .... 其他操作

同时我需要每过“y”毫秒从另一个在Lua中运行的程序从该CSV读取值。

while true do
        sim.wait(y)
        PoseTable = readcsvf_function('path/to/csv_file_test',',')
        -- 需要以下条件,因为有时readcsvf_function返回为空
        if  PoseTable ~= nil then
        ....操作

我的程序似乎可以工作,但我想知道是否有更合适的方法来完成这项工作,或者这段代码是否会引起我没有察觉到的可能的错误。

原文链接 https://stackoverflow.com/questions/69300712

点赞