passing arguments
Steve Holden
steve at holdenweb.com
Sun May 22 18:02:26 EDT 2005
Dennis Lee Bieber wrote:
> On Sun, 22 May 2005 16:12:06 -0400, Steve Holden <steve at holdenweb.com>
> declaimed the following in comp.lang.python:
>
>
>
>>Aren't we forgetting argv[0] here, or am I overlooking something (like,
>>you chopped it off without telling me?)?
>>
>
> argv[0] is often just the invocation name of the program/script
> itself, not really an argument to the function of the program.
>
And you think I don't know this? I was questioning the correctness of
the assertions of the post to which I was replying. Whether it's a real
argument or not in undoubtedly occupies an entry in sys.argv.
> script1.py
> -=-=-=-=-=-=-=-=-
> import sys
>
> for x in range(len(sys.argv)):
> print "Argument %s is %s" % (x, sys.argv[x])
> -=-=-=-=-=-=-=-=-
>
> (watch out for line wrapping)
>
> E:\UserData\Dennis Lee Bieber\My Documents>script1.py "These are the"
> Voyages
> Argument 0 is E:\UserData\Dennis Lee Bieber\My Documents\Script1.py
> Argument 1 is These are the
> Argument 2 is Voyages
>
> E:\UserData\Dennis Lee Bieber\My Documents>python script1.py "quoted
> arg" regular args
> Argument 0 is script1.py
> Argument 1 is quoted arg
> Argument 2 is regular
> Argument 3 is args
>
> E:\UserData\Dennis Lee Bieber\My Documents>
>
>
So?
regards
Steve
--
Steve Holden +1 703 861 4237 +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/
Python Web Programming http://pydish.holdenweb.com/
More information about the Python-list
mailing list