要将Python控制台的输出重定向到文件,可以使用以下方法:
python your_script.py > output.txt
with open('output.txt', 'w') as f:
print('Hello, World!', file=f)
import sys
with open('output.txt', 'w') as f:
sys.stdout = f
print('Hello, World!')
无论选择哪种方法,都可以将Python控制台的输出写入文件中。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:qt日志怎么输出到文件和控制台