【发布时间】:2020-02-19 12:39:24
【问题描述】:
这是下面给出的程序
导入操作系统 进口时间
- 索引=0
- file=open("out_{index}.txt", 'a')
- 当真:
- ps=os.system(f"speedtest.exe")
- file.append(ps)
- 索引+=1
- time.sleep(4)
【问题讨论】:
标签: python-3.x networking automation
这是下面给出的程序
导入操作系统 进口时间
【问题讨论】:
标签: python-3.x networking automation
我相信它是 file.write() 而不是 file.append()。
我想你每次都想写入一个新文件。
我会这样做。
import time
import os
index = 0
while True:
ps = os.system("speedtest.exe")
with open(f"out_{index}.txt", 'w+') as f:
f.write(ps)
index += 1
time.sleep(4)
但是,如果你想写在同一个文件中。
我会这样做。
import time
import os
with open("out_file.txt", 'a+') as f:
index = 0
while True:
ps = os.system("speedtest.exe")
f.write(ps)
index += 1
time.sleep(4)
【讨论】: