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
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?
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!