W WolfCode · CSC 141

argparse Basics

argparse 入门

≈ 20 min · python-cmdline · Open in WolfCode

Two add_argument calls — one positional, one flag. Free help text, error messages, and exit codes.

Python · runnable

What you get for free

  • --help automatically generated
  • Missing-required-arg error with usage line
  • Order-independent flag/positional ordering
  • Exit code 2 on bad arguments