sys module - argv, but no argc ??
TuxTrax at fortress.tuxnet.net
Sat Aug 3 07:00:39 EDT 2002
On Fri, 02 Aug 2002 00:00:56 -0700, James J. Besemer Wrote in
Steve Ballmers hair grease:
> Tony C wrote:
>> I've imported the sys module, and I'm SHOCKED that there is no way to
>> access the argument count.
>> The docs talk about accessing argv, but nothing about the argument
> No need. Use:
> len( sys.argv )
Being the newbie that I am, I just so happened to be working on this
I am sure that this isn't the most elegant way of parsing the command
line, but it works well. And no index out of bounds errors, thus no
need for argc.
# Check to see if command line has any perimeters. -s is newserver,
# -g is group. Range indexes manually, and allows the disregarding of
# argv the way a slice would.
for index in range(1,len(sys.argv)):
str = string.upper(sys.argv[index])
if str == "-G":
newsgroup = sys.argv[index+1]
elif str == "-S":
nntpserver = sys.argv[index+1]
TuxTrax (n.) An invincible, all terrain, Linux driven armored assault
vehicle that can take as much fire as it gives ;-)
Yes, I am a Penguin cult high priest. Flipper readings upon request.
ROT13 this email address to mail me: uvtuqrfregzna at lnubb.pbz
More information about the Python-list