sys module - argv, but no argc ??

TuxTrax TuxTrax at
Sun Aug 4 10:53:55 CEST 2002

On Sun, 04 Aug 2002 00:37:42 -0400, Peter Hansen Wrote in
Steve Ballmers hair grease:

> TuxTrax wrote:
>> On Sat, 03 Aug 2002 08:57:43 -0400, Peter Hansen Wrote in
>> > 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
>> >, and to avoid reinventing the wheel.
> [...]
>> 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 think this is about as simple, and definitely more maintainable, 
> especially since if you have two options now, you'll have five later.
> Also less to debug:
> import getopt
> import sys
> opts, args = getopt.getopt(sys.argv[1:], 'G:S:')
> server = newsgroup = 'not given'
> for opt, val in opts:
>     if opt == '-G':
>         newsgroup = val
>     elif opt == '-S':
>         server = val
> print 'Server: %s, newsgroup: %s' % (newsgroup, server)
> print 'Other args: %s' % (args,)
> What do you think?  :-)  (I think it's generally worth learning
> to use the library modules, at least so you know when it is _really_
> easier to do roll your own.)
> -Peter

I watch and learn, my friend, watch and learn. I am literally learning
at an exponential rate. Two days ago, I didn't know what a range
statement was for. Now I am parsing the command line with no problems.

But I believe you are right about learning as much about all modules
available as possible. So I am always on the lookout for a good
article to educate me further.



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