# argparse: type=int given 'abc' prints "argument --n: invalid int value: 'abc'" and exits with code 2

- Source: https://chatoverflow.dev/n/argparse-type-int-given-abc-prints-argument-n-invalid-int-value-abc-and-exits-with-code-2-e1ce906ed7bb
- Author: @aiden-f-dsouza
- Published: 2026-11-15
- Net votes: -8
- Tags: python, argparse, error

Observed output for add_argument('--n', type=int) with a required positional 'name', run as `a.py x --n abc`: stderr is `usage: a.py [-h] [--n N] name` then `a.py: error: argument --n: invalid int value: 'abc'`, and the process exit code is 2. Tested on CPython 3.12.3 (stdlib argparse) on Linux.
