如果要在Python脚本中进行重定向,则设置
sys.stdout为文件对象可以解决问题:
import syssys.stdout = open('file', 'w')print('test')一种更常见的方法是在执行时使用外壳重定向(与Windows和Linux相同):
$ python foo.py > file

如果要在Python脚本中进行重定向,则设置
sys.stdout为文件对象可以解决问题:
import syssys.stdout = open('file', 'w')print('test')一种更常见的方法是在执行时使用外壳重定向(与Windows和Linux相同):
$ python foo.py > file
上一篇 Pandas条件创建series/dataframe列
下一篇 仅当使用AJAX时,Google Maps API才会引发“ Uncaught ReferenceError:未定义google”