2022-11-27 Metavar of add_argument in python's argparse library

one word

This metavar is to enrich the help documentation and has no other effect.

detailed

Under normal circumstances, write a parameter directly, and in the help information displayed with -h, the second item is directly the uppercase letter of the parameter.
After using metavar, the second item of the output help information is the information in metavar.
adsf
What is the benefit of this parameter?
Imagine, if there is a parameter -p followed by a point coordinate [x, y], at this time, the metavar help information will be more concise and clear, as shown in the following figure:
insert image description here

Precautions

It should be noted that metavar and action cannot exist at the same time, because the action parameter does not need to parse the value behind the parameter, as long as there is this item in the parameter, it will be set as the value of action.So when the metavar and action parameters exist at the same time, an error will be reported!

おすすめ

転載: blog.csdn.net/Vissence/article/details/128065941