Keith Hughitt wrote:
Hi all,
I am using someone else's script which expects input in the form of:
./script.py <arg1> arg2
I was wondering if the angle-brackets here have a special meaning? It
seems like
they specify an input and output stream to use in place of the
console. I could not
find anything in the python manual or Python in a Nut-shell though.
Anyone know?
Thanks,
Keith
--
http://mail.python.org/mailman/listinfo/python-list
In most Unix/Linux and related OS shells, the angled brackets *do*
specify input and output streams as you surmise. However, they are
*not* seen by the script as command line arguments. (And they are
*not* brackets, and do not need to be matched. )
For any command,
cmd < file
redirects the contents of file to cmd's standard input, which in Python
is accessed by reading from sys.stdin (use input or raw_input or
sys.stdin.read...)
Also for any command,
cmd > file
redirects the output of cmd to the named file. In Python this can be
accessed using print, sys.stdout.write, ...
Anything written to sys.stderr will not be caught by the ">"
redirection, ans so will probably end up on the screen instead of in file.
Also various shells will provide similar functionality using a variety
of similar syntaxes: <<, >>, >&, and |, and so on.
Gary Herron
--
http://mail.python.org/mailman/listinfo/python-list