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 more appropriate than standard out.

- 4,612
- 2
- 27
- 42
-
it prints to stdout on python 3.4 – behzad.nouri Sep 25 '14 at 00:02
-
2its stderr in 3.2.3... we're narrowing it down! – tdelaney Sep 25 '14 at 00:10
-
6the behavior was changed by [this patch](https://hg.python.org/cpython/rev/e6384b8b2325) and was then added to 3.4 [release notes](https://hg.python.org/cpython/rev/fc089cf0cf32). original [bug report](http://bugs.python.org/issue18338) – behzad.nouri Sep 25 '14 at 00:20
-
2I dumped help to stderr back in the day. It was considered a friendly way to let your output be piped to other programs while still dumping help if a parameter was incorrect. Consumers down the pipeline didn't need to worry about their scanners/parsers getting messed up by unexpected text. Version numbers are help also, so it goes to stderr. – tdelaney Sep 25 '14 at 00:37
-
It's stderr in 3.3 too. – user1277476 Sep 25 '14 at 00:41
2 Answers
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!

- 420
- 1
- 6
- 10
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?
-
9I would say that in the case of `python --version` the version string is "the product of successful execution of the program". – aaaarrgh Oct 30 '17 at 22:18
-
Thanks for the effective differentiation in between ***stdout*** & ***stderr*** @Aaron. – testuser Jan 30 '19 at 14:45