python -c cmd bug?

Richard Walkington richard at stockcontrol.net
Wed Mar 13 08:22:25 EST 2002


erik.wilsher at iname.com (erik_w) wrote 
> When I do 
> >python -c "import sys;print sys.argv"
> ['-c']
> 
> (Python 2.1.2 on NT4)
> 
> Is this the right behaviour?  I would expect that the -c was an option
> to the python interpreter, not to my script.

Yup, it is correct. To quote the python tutorual:

"When known to the interpreter, the script name and additional
arguments thereafter are passed to the script in the variable
sys.argv, which is a list of strings. Its length is at least one; when
no script and no arguments are given, sys.argv[0] is an empty string.
When the script name is given as '-' (meaning standard input),
sys.argv[0] is set to '-'. When -c command is used, sys.argv[0] is set
to '-c'. Options found after -c command are not consumed by the Python
interpreter's option processing but left in sys.argv for the command
to handle. "

See http://www.python.org/doc/current/tut/node4.html#SECTION004100000000000000000

Regards
Richard Walkington



More information about the Python-list mailing list