Skip to content
Advertisement

Command line args accepting -SS also where as expected is -S using argparse

I have command line argument -S as defined below

JavaScript

but if I use -SS instead of -S, python doesn’t throw any error. I want invalid argument error. Can anybody tell me how to achieve this?

Advertisement

Answer

You need to use allow_abbrev=False in argparse.ArgumentParse

JavaScript

Output:

JavaScript

Error is raised when it is called with -SS

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement