Re: Difficulties in using optparse for the very first time.

Laura Creighton <[email protected]> Mon, 05 Jul 2004 07:30:34 +0200
Newsgroups gmane.comp.python.optik.user
Message-ID <[email protected]>
In a message of Sun, 04 Jul 2004 18:07:28 EDT, David Goodger writes:
>Hi Laura,
>
> > What am I doing wrong? There has _got_ to be an easier way to get
> > what I want than this.
>
>I think the root of the problem may be this:
>
> > "usage: %prog [-s [filename ...] | [-i|-c filename ...]]
>
>and:
>
> > Skipping the philosophy section,
>
>The command-line usage you desire is not supported by optparse.
>Specifically, optparse doesn't support "zero or more option arguments"
>as implied by the usage string.

I think it is only the second part.
>The usage line doesn't make clear what "filename" is.  Is it an input
>filename, or output filename?  I suspect it's the input filename, and
>that the program will support multiple input files (zero implying
>stdin for input).  I suspect that you really want this usage:
>
>     usage: %prog [-s | -i | -c] [input_filename ...]

No, I don't want this, because this implies that input_filename(s) are
optional.  That is only the case with the -s option, or if you pass it
no options at all.  input_filenames(s) are required with the -i and the -c option.

And this is the heart of the disagreement.  I think that almost all programs
which do not read from stdin and write to stdout by default are badly written
w.r.t. their option parsing.  (The great exception being gui-driven programs).  
Unless you are controlling your program by mouseclicks, sooner or later somebody 
is going to come along and want to use your program as a script in a pipeline.  
So what you are not supporting is something that I consider essential.

The odd thing is that I was unaware of the controversy.  I knew that some
people, especially people who program for windows and have never used a pipe,
were _unaware_ that they should write their programs to take file name
arguments if they are there, or stdin if they are not, but I was unaware that
some people were actually opposed to this.  I suppose I should get out more.

Laura




-------------------------------------------------------
This SF.Net email sponsored by Black Hat Briefings & Training.
Attend Black Hat Briefings & Training, Las Vegas July 24-29 - 
digital self defense, top technical experts, no vendor pitches, 
unmatched networking opportunities. Visit www.blackhat.com