[Tutor] opts and try except

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Fri Nov 18 06:49:09 CET 2005



On Thu, 17 Nov 2005, Eric Walker wrote:

> I have a program now that works just like I want it. Now I want to
> integerate something to say print usage info when the user puts in the
> wrong number or type of options. Also print usage say if you type
> program name and -h or -H. I currently just have functions defined and
> at the bottom make a function call. Do I need to do like the def main():
> and then the if __name__ == "__main__"? I need an example of how to
> implement this.


Hi Eric,

Yes, there's a whole option-parsing system called 'optparse' that handles
option-parsing and the -h documentation generator:

    http://www.python.org/doc/lib/module-optparse.html

The examples in the documentation there should help you get started.


If you have more questions, though, please feel free to ask.  Good luck!



More information about the Tutor mailing list