sys module - argv, but no argc ??
Gabe.Newcomb at noetix.com
Fri Aug 2 15:13:17 EDT 2002
Yes indeed. I felt I needed to comment, however, since one of the
respondents told the OP that len(sys.argv) returns the number of args
passed, and that's not true if you consider args to be those things
passed in addition to the calling script/process.
From: Terry Reedy [mailto:tjreedy at udel.edu]
Sent: Friday, August 02, 2002 11:32 AM
To: python-list at python.org
Subject: Re: sys module - argv, but no argc ??
"Gabe Newcomb" <Gabe.Newcomb at noetix.com> wrote in message
news:mailman.1028302925.9447.python-list at python.org...
>But beware that sys.argv includes the script as the first item
So does argv in C
> so if you do: len(sys.argv) you will actually get the number of args
passed + 1.
Which is also true of argc in C. Python is here mimicking C, which is
what the O.P. wanted. Standard loop:
for (i = 1 /*not 0*/, i < argc, i++) process(arg[i]);
for i in argv[1:]: process(i)
Terry J. Reedy
More information about the Python-list