There are several ways to populate the parser with options. Thepreferred way is by usingOptionParser.add_option(), as shown insection 14.3.2, the tutorial.add_option() can be called in one of twoways:
The other alternative is to pass a list of pre-constructed Optioninstances to the OptionParser constructor, as in:
option_list = [ make_option("-f", "--filename", action="store", type="string", dest="filename"), make_option("-q", "--quiet", action="store_false", dest="verbose"), ]parser = OptionParser(option_list=option_list)(make_option() is a factory function for creating Option instances;currently it is an alias for the Option constructor. A future versionofoptparse may split Option into several classes, andmake_option()will pick the right class to instantiate. Do not instantiate Optiondirectly.)