使用 micro python,我尝试将 stderr 重定向到文件,但是我无权访问板上的运行命令,因此我无法执行任何 shell 重定向命令,例如
>> > |
。我很好奇是否有办法在 Micropython 中做到这一点。
我已经尝试过了
import sys
sys.stdout = open('out.txt', 'w')
sys.stderr = sys.stdout
然而
https://forum.micropython.org/viewtopic.php?t=2091<- this discussion mentions that it is not a method supported. Im curious if y'all have any ideas. Most my googling leads itself to just python instead of micropython.
但出现错误,指出模块没有名为 stdout 的属性 谢谢
这是我一直用来将控制台输出记录到文件的脚本
import io, os
class logToFile(io.IOBase):
def __init__(self):
pass
def write(self, data):
with open("logfile.txt", mode="a") as f:
f.write(data)
return len(data)
# Begin loging to file
os.dupterm(logToFile())
# Stop loging to file
os.dupterm(None)
在树莓派Pico W上遇到同样的问题,你找到解决方案了吗?