[Tutor] getopts question

Andreas Kostyrka andreas at kostyrka.org
Fri Mar 30 13:41:00 CEST 2007


* Kent Johnson <kent37 at tds.net> [070330 13:04]:
> Greg Perry wrote:
> > Hello List Members,
> > 
> > I am working on a simple program and would like to know the best way
> to approach this. Using getops I am parsing the argv array to grab
> command line options; from the command line the user can specify either
> a filename or a directory (but not both). Is there an eloquent way with
> getopts to do an either/or scenario without resorting to multiple tests
> to see which variable is set using if then statements?
> 
> I'm not really sure what you are looking for here. If you use two 
> options, you will have to test to see which option is set. You could use 
> one option, then you will have to test to see if the value is a file or 
> a directory.

Alternativly, use the module optparse, which is a little bit more high
level than getopt.

Andreas


More information about the Tutor mailing list