[Tutor] Command line arguments passing
Alan Gauld
alan.gauld at freenet.co.uk
Sun Dec 4 10:00:13 CET 2005
> 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?
What did you get when you tried it?
I ran:
#######test.py ######
import sys
print sys.argv
###################
python test.py foo "long name" bar
and got
['testargv.py', 'foo', 'long name', 'bar']
What did you get? Since its much less typing to try it than to ask
the question I assume you must have had a problem with it?
Alan G
Author of the learn to program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld
and got
I am specifically interested in
> whether argv[2]=="\"Long" or argv[2]=="Long name", that is, if the shell
> does the processing or I need to do it in the program. Also, I need to
> know if most environments do the same (I wouldn't want to be caught
> pants down while porting this to Windows).
>
> Many thanks in advance for your valuable suggestions and apologies if I
> have misposted,
>
> Vlad
>
>
>
>
More information about the Tutor
mailing list