optparse — Parser for command line options — Python 3.16.0a0 documentation

docs.python.org

Tin mới

Migrating optparse code to argparse

getpass — Portable password input

Python Module Index

3.16.0a0 Documentation

The Python Standard Library

Command-line interface libraries

getopt: Portable parser for command line options; support both short and long option names.

getopt: a module that closely mirrors the procedural C getopt API. Included in the standard library since before the initial Python 1.0 release.

argparse: Command-line option and argument parsing library.

argparse: a more opinionated alternative to optparse that provides more functionality by default, at the expense of reduced application flexibility in controlling exactly how arguments are processed. Included in the stan

How optparse handles errors¶

There are two broad classes of errors that optparse has to worry about: programmer errors and user errors. Programmer errors are usually erroneous calls to OptionParser.add_option(), e.g. invalid option strings, unknown

Standard option types¶

optparse has five built-in option types: "string", "int", "choice", "float" and "complex". If you need to add new option types, see section Extending optparse.

copy: Shallow and deep copy operations.

To add new types, you need to define your own subclass of optparse’s Option class. This class has a couple of attributes that define optparse’s types: TYPES and TYPE_CHECKER.