{"record":{"id":"3ca4eec98ddfe3a6","repo":"python/cpython","slug":"unknown-option-c-n","errorCode":null,"errorMessage":"Unknown option: -%c\\n","messagePattern":"Unknown option: -%c\\\\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"Python/getopt.c","lineNumber":138,"sourceCode":"        }\n        opt_ptr = L\"\";\n        if (!opt->has_arg) {\n            return opt->val;\n        }\n        if (_PyOS_optind >= argc) {\n            if (_PyOS_opterr) {\n                fprintf(stderr, \"Argument expected for the %ls options\\n\",\n                        argv[_PyOS_optind - 1]);\n            }\n            return '_';\n        }\n        _PyOS_optarg = argv[_PyOS_optind++];\n        return opt->val;\n    }\n\n    if ((ptr = wcschr(SHORT_OPTS, option)) == NULL) {\n        if (_PyOS_opterr) {\n            fprintf(stderr, \"Unknown option: -%c\\n\", (char)option);\n        }\n        return '_';\n    }\n\n    if (*(ptr + 1) == L':') {\n        if (*opt_ptr != L'\\0') {\n            _PyOS_optarg  = opt_ptr;\n            opt_ptr = L\"\";\n        }\n\n        else {\n            if (_PyOS_optind >= argc) {\n                if (_PyOS_opterr) {\n                    fprintf(stderr,\n                        \"Argument expected for the -%c option\\n\", (char)option);\n                }\n                return '_';\n            }","sourceCodeStart":120,"sourceCodeEnd":156,"githubUrl":"https://github.com/python/cpython/blob/bc6749cc3b5ae4a5e88a6cc2d5b3bebbe354eae6/Python/getopt.c#L120-L156","documentation":"Emitted by CPython's getopt replacement (Python/getopt.c) when a short option character is not found in the SHORT_OPTS string (wcschr returns NULL). The interpreter does not recognize that flag letter, so it prints 'Unknown option: -X' and returns '_', causing command-line parsing to fail with a usage message.","triggerScenarios":"Passing a single-character option that CPython does not implement, e.g. `python -z script.py`, or a bundled short-option group containing an invalid letter (e.g. `-vq` if one letter is unsupported), or using an option spelling meant for a different tool/version (e.g. a flag removed or renamed between Python versions).","commonSituations":"Copy-pasting a command written for a different Python version or another interpreter (PyPy, Python 2) that supported different flags; typos like `-Ve` instead of `-V`; scripts that assume a flag exists without checking the Python version.","solutions":["Run `python -h` to list valid options for the exact interpreter in use and correct the flag","Check for version drift: the flag may exist only in newer/older CPython (consult the version's command-line docs)","Look for typos or shell-quoting artifacts that mangled the option character"],"exampleFix":"# before\npython -Bd -uq script.py   # -q is not a CPython option\n# after\npython -Bd -u script.py","handlingStrategy":"validation","validationCode":"# Validate flags against the running interpreter before launch\npython -h 2>&1 | grep -q -- '-u' || { echo 'unsupported flag'; exit 1; }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pin the Python version your scripts target so flag sets are known","Check `python -h` output when adding a new flag to scripts","Prefer long forms (--version, --check-hash-based-pycs) over short letters; they fail more loudly when misspelled"],"tags":["cli","command-line","getopt","cpython","typo"],"backgroundTag":null,"analyzedSha":"bc6749cc3b5ae4a5e88a6cc2d5b3bebbe354eae6","analyzedAt":"2026-08-14T22:01:13.976Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}