sys module - argv, but no argc ??

Terry Reedy tjreedy at udel.edu
Fri Aug 2 21:52:10 EDT 2002


"Gabe Newcomb" <Gabe.Newcomb at noetix.com> wrote in message
news:mailman.1028315645.26194.python-list at python.org...
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.

Me: I wasn't contradicting your warning, just the implication (perhaps
not meant by you) that Python was doing anything extra 'wrong' or
'misleading'.  C programmers also need the warning.  K&R (The C
Programming Language) first call argc "the number of command-line
arguments" (p.110) and only later explain (next page) that it is
actually one more.

"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.






More information about the Python-list mailing list