Project Home


Addition to optparse to automatically parse and store the arguments.

Table of Contents


Addition to optparse to automatically parse and store the arguments.

This module provides a new class OptionParserWithArgs() that allows specifying the contents of the arguments (always non-optional) and that places the results on the resulting options container object rather than return the arguments.

10 Second User Guide

Use it like this:

import optparse_wargs as optparse

parser = optparse.OptionParserWithArgs(...)

parser.add_argument('dbname', 'The database name to work on.')
parser.add_argument('dumpfile', 'The dump file to work on.')

opts = parser.parse_args()

# Use opts.dbname, opts.dumpfile, ...


  • The parse_args() function does not return the arguments anymore, they are stored on the options object.
  • Collisions between option attribute names and argument names are detected. Specifying an incorrect number of arguments will fail automatically.
  • The generated usage help now includes the documentation for the arguments.
  • When you add an argument, you can specify how many of the arguments to consume. Using -1 will store all the remaining arguments in the destination.

To Do

  • We need to submit this to Optik.
  • Write tests.
  • Actions would be convenient for arguments as well.

Please Donate!


This computer program or library is provided for free. I am aware that some of the programs that I provide for free allow people to get their work done faster or better, save them time and money. If you are using this program for benefit, especially if you are using it within a commercial environment and it saves you time or work, please consider making a donation by sending me a book from my Amazon Wishlist or by a direct donation to my company's PayPal account by clicking on the link below.


Download program here.