liveBook · Manning

Argparse

argparse is Python’s standard-library module for defining and parsing command-line arguments and generating related usage, help, and error information.

How 3 Manning books explain it

The Quick Python Book, Fourth Edition

argparse is Python's standard-library module for parsing command-line arguments and generating related help and error messages.

How it is used
Parses positional arguments and options for command-line scripts, including a wc-style file-counting utility.
How deep it goes
Works through parser setup, types, defaults, flags, and Namespace values, then applies optional file handling and stdin.
Examples
Uses a report-options script and a wc-style counter with selectable counts and redirected input.
What you can do after
Build it from scratch: configure a parser, read its Namespace, and accept either a filename or stdin.

Read how The Quick Python Book, Fourth Edition explains argparse →

Tiny Python Projects: Learn coding and testing with puzzles and games

argparse is a Python standard-library module for parsing command-line arguments and generating related usage and help information.

How it is used
Parses and documents command-line inputs while validating values before program processing.
How deep it goes
Explains positional, optional, flag, nargs, choices, type, and file arguments through repeated runnable programs, without internal implementation details.
Examples
Uses greeting commands, picnic lists, readable files, dictionary lookups, and vowel substitution to demonstrate argument definitions.
What you can do after
Build command-line programs that parse, validate, document, and organize user input with reusable get_args() functions.

Read how Tiny Python Projects: Learn coding and testing with puzzles and games explains argparse →

Django in Action

argparse is a Python standard-library module for parsing command-line arguments and converting them into structured values.

How it is used
Parses command-line input for Django management commands and supplies flags or positional values to command logic.
How deep it goes
Explains operating-system strings, parser registration, flags, abbreviations, and practical filtering, while deferring argparse’s broader complexity.
Examples
Uses a musicians command with name and birth-date filters, abbreviated flags, combined filters, and invalid-date handling.
What you can do after
Apply it through Django’s add_arguments() method to register and use management-command inputs.

Read how Django in Action explains argparse →

Related concepts

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.