【发布时间】:2021-09-12 01:38:23
【问题描述】:
这是一个简化的例子,python程序在设备上运行,等待一个文本文件来理解下一步如何执行,文本文件会频繁上传到设备。
如何让python程序将文本文件(本例中steps.txt只有一行"z = x + y")“翻译”成可执行脚本?
import os
import time
x = 3
y = 9
s = None
while 1:
time.sleep(1)
try:
with open("steps.txt", 'r') as f:
s = f.readline()#s = "z = x + y"
f.close()
break
except:
pass
os.system(s)#'z' is not recognized as an internal or external command,operable program or batch file.
【问题讨论】:
标签: python