Why does python print version info to stderr?

前端 未结 2 1645
攒了一身酷
攒了一身酷 2020-11-30 09:10

Why did Guido (or whoever else) decide to make python --version print to stderr rather than stdout? Just curious what the use case is that makes standard error

相关标签:
2条回答
  • 2020-11-30 09:26

    Many programs would just use stdout and not care but I would prefer stderr on principle. In short, I believe stdout is for the product of successful execution of a program while stderr is for any messages meant for the user. Calculated values go to stdout while errors, stack traces, help, version and usage messages are meant for the user and should go to stderr.

    I use this question to decide which to output stream is appropriate: Is this message meant for the consumer of the main product of this program (whether that's the human user or another program or whatever) or is it strictly for the human user of this program?

    Also, looks like Java uses stderr for version messages as well by the way: Why does 'java -version' go to stderr?

    0 讨论(0)
  • 2020-11-30 09:34

    Python 3.4 was modified to output to stdout, which is the expected behavior. This is listed as a bug with Python here: http://bugs.python.org/issue18338. The comments on the bug report indicate that while stdout is the reasonable choice, it would break backward compatibility. Python 2.7.9 is largely unchanged, because so much relies on it.

    Hope that helps!

    0 讨论(0)
提交回复
热议问题