sys module - argv, but no argc ??

Terry Reedy tjreedy at udel.edu
Fri Aug 2 14:32:10 EDT 2002


"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
(sys.argv[0]),

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]);

In Python:

for i in argv[1:]: process(i)

Terry J. Reedy







More information about the Python-list mailing list