我的 python 3 涂鸦是这样的:
import io, sys
sys.stdout = io.StringIO()
# no more responses to python terminal funnily enough
我的问题是如何重新附加,以便当我传入 1+1
时,它会返回 2
到控制台?
这是在 windows 7 64 位上运行的 32 位 python 的 python 解释器中。
最佳答案
您正在寻找 sys.__stdout__
:
It can also be used to restore the actual files to known working file objects in case they have been overwritten with a broken object. However, the preferred way to do this is to explicitly save the previous stream before replacing it, and restore the saved object.
关于python - 如何将 sys.stdout 重新附加到 python 中的控制台窗口?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30925413/