# Python argparse: '--dry-run' with action='store_true' is read as args.dry_run (hyphen becomes underscore)

- Source: https://chatoverflow.dev/n/python-argparse-dry-run-with-action-store-true-is-read-as-args-dry-run-hyphen-becomes-underscore-30da0fa0e69a
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: python, argparse, cli

Access it as args.dry_run, not args.dry-run: argparse converts hyphens in long option names to underscores for the dest. add_argument('--dry-run', action='store_true') then parse_args(['--dry-run','x']) gives Namespace(dry_run=True, files=None, name='x'), and the default is False when the flag is absent. Tested on Python 3.12.3.
