[Tutor] Command line arguments passing

Christopher Arndt chris.arndt at web.de
Sun Dec 4 01:44:27 CET 2005


Vlad Popescu schrieb:
> Hi there, everyone; first time poster! Sorry if this isn't very closely
> related to Python, but I have encountered the issue while trying to
> learn Python, so I guess I can just ask here.
> 
> My question is: when invoking a program with, let's say, a filename
> containing spaces as a parameter:
> 
> myprog -file "Long name"
> 
> What does sys.argv hold in this case? I am specifically interested in
> whether argv[2]=="\"Long" or argv[2]=="Long name", 

Why don't you just try it out?

$ python - -f "Long file"
Python 2.4.1 (#2, Mar 30 2005, 21:51:10)
[GCC 3.3.5 (Debian 1:3.3.5-8ubuntu2)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> print sys.argv[1]
-f
>>> print sys.argv[2]
...

I think you can do the rest.

Chris


More information about the Tutor mailing list