我搜索了Google,Stack Overflow和我的Python用户指南,但没有找到一个简单,可行的答案.
我在Windows 7 x64计算机上创建了一个文件c:\ goat.txt,并尝试将"test"打印到该文件.我根据StackOverflow上提供的示例尝试了以下内容:
此时我不想使用日志模块,因为我从文档中无法理解基于二进制条件创建简单日志.打印很简单但是如何重定向输出并不明显.
一个简单明了的例子,我可以进入我的interperter是最有帮助的.
此外,赞赏任何信息网站的建议(不是pydocs).
import sys
print('test', file=open('C:\\goat.txt', 'w')) #fails
print(arg, file=open('fname', 'w')) # above based upon this
print>>destination, arg
print>> C:\\goat.txt, "test" # Fails based upon the above
Run Code Online (Sandbox Code Playgroud)