Martin Panter added the comment: This is actually expected behaviour of the “argparse”, as well as general Unix CLI programs. See the documentation <https://docs.python.org/3.6/library/argparse.html#arguments-containing>. The general workaround is to use a double-dash separator:
>>> parser.parse_args(['--', '-_']) Namespace(first='-_') Example with the Gnu “rm” command: $ echo "make a file" >-_ $ rm -_ rm: invalid option -- '_' Try 'rm ./-_' to remove the file '-_'. Try 'rm --help' for more information. [Exit 1] $ rm -- -_ # Double dash also works Although I suppose the error message could be improved. Currently it looks like it ignores the argument: >>> parser.parse_args(['-_']) usage: [-h] first : error: the following arguments are required: first __main__.SystemExit: 2 ---------- nosy: +martin.panter _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue29715> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com