sys module - argv, but no argc ??

Gabe Newcomb Gabe.Newcomb at
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.


-----Original Message-----
From: Terry Reedy [mailto:tjreedy at]
Sent: Friday, August 02, 2002 11:32 AM
To: python-list at
Subject: Re: sys module - argv, but no argc ??

"Gabe Newcomb" <Gabe.Newcomb at> wrote in message
news:mailman.1028302925.9447.python-list at

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

In Python:

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

Terry J. Reedy


More information about the Python-list mailing list