2024-04-26 12:27:54 发布
网友
我经常使用myFile.write("..."),有时我希望在控制台中看到输出,而不是重新打开更新的文件。我在用空闲的。你知道吗
myFile.write("...")
所以,我想知道,在设置myFile变量时,我是否可以用STDIO之类的东西替换文件名(output.txt),而不是到处用myFile.write()替换print()?你知道吗
output.txt
myFile.write()
print()
myFile = open("output.txt", "w")
给你:sys.stdout。就像其他文件句柄一样使用它。例如
print >> sys.stderr, "Hi! I'm an error!"
您可以使用sys模块。。。你知道吗
sys
import sys myFile=sys.stdout myFile.write("Hello!\n")
sys.stderr也可用。你知道吗
sys.stderr
给你:sys.stdout。就像其他文件句柄一样使用它。例如
您可以使用
sys
模块。。。你知道吗sys.stderr
也可用。你知道吗相关问题 更多 >
编程相关推荐