[Tutor] Unix philosophy
alan.gauld at blueyonder.co.uk
Tue Nov 18 12:56:57 EST 2003
> That means that if I wanted to do it in a more general
> way that with fileinput module I should use the
> sys.stdin/out functions?
> Are you thinking to something like this:
> # Simple cat UNIX command
> import sys
> if len(sys.argv)==1:
> for files in sys.argv[1:]:
Exactly so. If no filename is provided assume it's stdin.
Another often seen trick is to have a flag for using as a filter
(Unix tar is an example) so you specify the tar filename as "-f file"
and if the name is '-' use stdin.
tar cvf foo.tar
writes the output to foo.tar
tar cvf -
writes the output to stdout (usually a pipe to another command)
But your way is a perfectly valid way too.
More information about the Tutor