【问题标题】:Can I redirect my python/ipython input/output to a text file? [duplicate]我可以将我的 python/ipython 输入/输出重定向到文本文件吗? [复制]
【发布时间】:2017-05-15 06:07:39
【问题描述】:

我希望我在 python/ipython 命令行中输入的内容也可以重定向到文件。 另外,我希望将输出文本捕获到文件中。

有什么选择,或者内部函数可以帮助解决这个问题吗?

【问题讨论】:

  • python script.py > output.txt 。 Linux 也有命令tee 将管道同时重定向到文件和屏幕上。 python script.py | tee output.txt
  • 你可以试试echo "input text" | tee input.txt | python script.py,也可以echo "input text" | tee input.txt | python script.py | tee output.txt
  • 看看这个this。查看ipython 在您的计算机上创建和更新的sqlite db 也可能会有所帮助。它通常位于~/.ipython/profile_default,称为history.sqlite

标签: python redirect text input option


【解决方案1】:

它们最简单的方式,正如“furas”已经说过的那样是“>”和“python myfile.py < input.txt > output.txt

【讨论】:

    猜你喜欢
    • 2013-01-12
    • 1970-01-01
    • 2015-04-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-22
    相关资源
    最近更新 更多