
如果要在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
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)