上QQ阅读APP看书,第一时间看更新
There's more...
You can create long arguments as well with double dashes, for example:
parser.add_argument('-v', '--verbose', action='store_true', default=False,
help='Enable verbose output')
This will accept both -v and --verbose, and it will store the name verbose.
Adding long names is a good way of making the interface more intuitive and easy to remember. It's easy to remember after a couple of times that there's a verbose option, and it starts with a v.
The main inconvenience when dealing with command-line arguments may be ending up with too many of them. This creates confusion. Try to make your arguments as independent as possible and not make too many dependencies between them, or handling the combinations can be tricky.
In particular, try to not create more than a couple of positional arguments, as they won't have mnemonics. Positional arguments also accept default values, but most of the time that won't be the expected behavior.
For advanced details, check the Python documentation of argparse (https://docs.python.org/3/library/argparse.html).