Standard input, often called STDIN, is the command line’s standard place for reading input. In Python, sys.stdin is the always-available text stream object used when a program receives no file arguments. section 6.0 section 6.1.1
A program can receive standard input in two common ways:
- Pipe another program’s standard output into it with |. section 6.0
- Redirect a file into it with <. section 6.0
- Use argparse with nargs='*' and default=[sys.stdin] to accept zero or more readable text files, falling back to standard input. section 6.1.1
Pipe text into a counter
$ grep scarlet ../inputs/*.txt | ./wc.py 108 1192 9201 <stdin> The same program can read a file through shell redirection: $ ./wc.py < ../inputs/fox.txt 1 9 45 <stdin> section 6.0
Figure 6.1 A string diagram showing that wc.py will read one or more file inputs or possibly STDIN and will produce a summary of the words, lines, and bytes contained in each input.
Maps the input choices—files or STDIN—to the program’s line, word, and byte summary. section 6.1.1




