Short form of argparse option permisive of many ch

2019-08-02 17:15发布

I was checking this python file where it seems to use a short argument with 2 characters.

parser.add_argument(
    '-gt',
    '--gtfolder',
    dest='gtFolder',
    metavar='',
    help='folder containing your ground truth bounding boxes')

I thought short arguments were meant to contain only a single character and that came as a surprise to me. Indeed in the documentation it states that short options (options only one character long)....

On the other hand the code seems to work (at least as regards argparse options).

I checked the code and it's getting the correct argument if the short form is used.

python3 pascalvoc.py -gt 'path/somewhere'

The only malfunction I noticed is that the concatenated version of the code does not work:

python3 pascalvoc.py -gt'path/somewhere'

... error: unrecognized arguments: -gtpath/somewhere

So, my question is why short options with more than 1 character are permitted in the first place. This could go unnoticed if not for the concatenated version. Also apart from the fact that one hyphen minus is necessary in the short form this seems to bypass the mere rule that short should be shorter than long. In that sense, this is functional (if not concatenated option is applied of course):

parser.add_argument(
    '-gt-not-short-at-all-argument',
    '--gtfolder',
    dest='gtFolder',
    metavar='',
    help='folder containing your ground truth bounding boxes')

0条回答
登录 后发表回答