【问题标题】:How to make `python2 -V >> myfile` "work"? [duplicate]如何使`python2 -V >> myfile`“工作”? [复制]
【发布时间】:2016-08-31 08:43:48
【问题描述】:

我想在 computerinfo 文件中自动记录我的 python 版本。不过

python2 -V >> myfile

只打印到控制台而不是myfile。如何将输出保存到文件中?

奇怪的是,对于 python3 -- python3 -V >> myfile -- 这符合我的预期。

我在 Ubuntu 16.04 上使用 bash shell。

【问题讨论】:

  • 你需要重定向stderr,像这样:python2 -V 2>> myfile

标签: python bash file-io output


【解决方案1】:

python2 -V 中有一个错误,它将版本打印为stderr 而不是stdout。尝试重定向stderr 喜欢:

python2 -V 2>> myfile

【讨论】:

    猜你喜欢
    • 2022-08-07
    • 2012-03-31
    • 2023-03-12
    • 1970-01-01
    • 2019-07-11
    • 2017-04-09
    • 1970-01-01
    • 1970-01-01
    • 2018-06-11
    相关资源
    最近更新 更多