liveBook · Manning

Help option

As explained in Tiny Python Projects: Learn coding and testing with puzzles and games

A help option is a command-line option that requests usage information and other program documentation.

A help option is a command-line option that requests usage information and program documentation. Python’s argparse module commonly provides -h and --help automatically. section 1.7 section 2.1.4

Inspecting a program’s interface

Running ./hello.py -h prints the usage pattern, description, positional arguments, and the help option itself. Running without the required name instead prints usage and an error. section 1.7 section 2.1.4

A help option can:

  • Document positional arguments and optional parameters. section 2.1.4
  • Show defaults, accepted inputs, and a program description. section 19.1
  • Provide immediate guidance before normal program execution. section 1.7
$ ./hello.py -h
usage: hello.py [-h] name
 
Say hello
 
:
  name        Name to greet      #1
 
:
  -h, --help  show this help message and exit

Use the terminal listing to compare the concise command with the structured usage information it produces. section 1.7

How Tiny Python Projects: Learn coding and testing with puzzles and games covers it

How deep it goes
Defines generated usage output and demonstrates argparse configuration, but does not descend into parser internals.
Examples
Demonstrates -h and --help with hello.py, crowsnest.py, wc.py, friar.py, and wod.py.
What it assumes
Builds from runnable Python programs and command-line arguments before introducing automatic help generation.
What you can do after
Apply it via Python’s argparse module to generate documented command-line interfaces.
How it connects
Connects command-line arguments, argparse, positional arguments, and usage statements.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Tiny Python Projects: Learn coding and testing with puzzles and games. The section links point to the parts of the book it draws on.