DAGDA SEARCH | Back to results | Support

Migrating optparse code to argparse — Python 3.16.0a2 documentation

Source: https://docs.python.org/dev/howto/argparse-optparse.html

Navigation

Migrating optparse code to argparse

The argparse module offers several higher level features not natively provided by the optparse module, including:

Originally, the argparse module attempted to maintain compatibility with optparse. However, the fundamental design differences between supporting declarative command line option processing (while leaving positional argument processing to application code), and supporting both named options and positional arguments in the declarative interface mean that the API has diverged from that of optparse over time.

As described in Choosing an argument parsing library, applications that are currently using optparse and are happy with the way it works can just continue to use optparse.

Application developers that are considering migrating should also review the list of intrinsic behavioural differences described in that section before deciding whether or not migration is desirable.

For applications that do choose to migrate from optparse to argparse, the following suggestions should be helpful:

Previous topic

Argparse Tutorial

Next topic

optparse — Parser for command line options

This page

«

Navigation

© Copyright 2001 Python Software Foundation.
This page is licensed under the Python Software Foundation License Version 2.
Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.
See History and License for more information.

The Python Software Foundation is a non-profit corporation. Please donate.

Last updated on Nov 29, 2026 (04:54 UTC). Found a bug?
Created using Sphinx 9.1.1.