从python编写CSV并从Lua读取

2024-05-15 15:07:53 发布

您现在位置:Python中文网/ 问答频道 /正文

我必须每隔“x”毫秒在CSV文件中连续写入一些值(CSV被重写)。我的做法如下:

while(True):
    time.sleep(x)
    with open('path/to/csv_file_test', 'w') as f:
        # create the csv writer
        writer = csv.writer(f)
        .... do other things

我必须在同一时间,每隔“y”毫秒,从Lua中的另一个程序读取这个CSV的值

while true do
        sim.wait(y)
        PoseTable = readcsvf_function('path/to/csv_file_test',',')
        -- need the following condition because sometimes readcsvf_function return nothing 
        if  PoseTable ~= nil then
        ....do things

我的程序似乎可以运行,但我想知道是否有更合适的方法来实现这一点,或者这段代码是否可能导致我没有发现的错误


Tags: csvthetopathtest程序functiondo