📜  在 python + Cout 中输出文本文件的最快方法 - Python 代码示例

📅  最后修改于: 2022-03-11 14:45:35.918000             🧑  作者: Mango

代码示例1
import sys

print('This message will be displayed on the screen.')

original_stdout = sys.stdout # Save a reference to the original standard output

with open('filename.txt', 'w') as f:
    sys.stdout = f # Change the standard output to the file we created.
    print('This message will be written to a file.')
    sys.stdout = original_stdout # Reset the standard output to its original value