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.
Python also provides the sys. stderr. write() method which can be used to print into the standard error or stderr.
Stderr is the standard error message that is used to print the output on the screen or windows terminal. Stderr is used to print the error on the output screen or window terminal. Stderr is also one of the command output as stdout, which is logged anywhere by default.
Python stderr is known as a standard error stream. It is similar to stdout because it also directly prints to the console but the main difference is that it only prints error messages. Example: import sys sys.stderr.write("This is error msg")
Every running program has a text output area called "standard out", or sometimes just "stdout". The Python print() function takes in python data such as ints and strings, and prints those values to standard out.
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!
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?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With