sys module - argv, but no argc ??

TuxTrax TuxTrax at fortress.tuxnet.net
Sat Aug 3 22:11:42 CEST 2002


On Sat, 03 Aug 2002 08:57:43 -0400, Peter Hansen Wrote in
Steve Ballmers hair grease:

> TuxTrax wrote:
>> 
>> 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[0] the way a slice would.
>> 
>> import string
>> import sys
> 
> [snip code]
> 
> You're probably right that it's not the most elegant way.  The
> most elegant way might be to use one of the existing modules,
> perhaps getopt from the standard library, or Optik at
> http://optik.sourceforge.net, and to avoid reinventing the wheel.
> 
> -Peter

Thank you peter. As I said, I am a newbie. I always appreciate
pointers from those who are experienced.

It does seem to me that if I am parsing the command line for two
options only, this snippet of code would be the way to go rather than
import a library to do it. I am sure that if I was doing any serious
parsing, I might want to use a library designed to do it. What do you think?

I didn't know about getopt. Thank you for the reference.

Cheers,

Mathew

-- 
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 mailing list