Q: argparse.add_argument()

Thomas Passin list1 at tompassin.net
Sat Mar 18 15:08:26 EDT 2023


On 3/18/2023 2:02 PM, Gisle Vanem via Python-list wrote:
> I accidentally used 'argparse' like this in my Python 3.9 program:
>    parser.add_argument ("-c, --clean",  dest="clean", action="store_true")
>    parser.add_argument ("-n, --dryrun", dest="dryrun", action="store_true")
> 
> instead of:
>    parser.add_argument ("-c", "--clean",  dest="clean", 
> action="store_true")
>    parser.add_argument ("-n", "--dryrun", dest="dryrun", 
> action="store_true")
> 
> So any use of 'my-prog.py -cn' threw an error:
>    error: unrecognized arguments: -cn
> 
> So is there something that throws an error on this wrong use of
> "-c, --clean" instead? Could be useful. Or is "-c, --clean" legit somehow?


Are you trying to troll here?  You just showed how you got an error with 
this construction, so why are you asking how to get an error with this 
construction?



More information about the Python-list mailing list