Understanding stdin stdout stderr

Alex Mollberg picture Alex Mollberg · Jan 28, 2013 · Viewed 19.7k times · Source

I'm trying to understand stdin stdout and stderr.

I see them used in people's code all the time and I can't understand exactly what they are. I am assuming that they have something to do with input/output but have been searching for an explanation online and can't find one. Does anybody know of a good link with an explanation or if it is simple enough to explain it would be a great help to me.

Since I am learning Python 3, examples in that would be helpful.

Answer

Suku picture Suku · Jan 28, 2013
sys.stdin
sys.stdout
sys.stderr

File objects used by the interpreter for standard input, output and errors:

  • stdin is used for all interactive input (including calls to input());

  • stdout is used for the output of print() and expression statements and for the prompts of input();

  • The interpreter’s own prompts and its error messages go to stderr.

For your more understanding:

>>> import sys
>>> for i in (sys.stdin, sys.stdout, sys.stderr):
...     print i
... 
<open file '<stdin>', mode 'r' at 0x103451150>
<open file '<stdout>', mode 'w' at 0x1034511e0>
<open file '<stderr>', mode 'w' at 0x103451270>

mode r means reading and mode w means writing