Short form of argparse option permisive of many characters

本小妞迷上赌 提交于 2019-12-11 12:51:58

问题


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')

来源:https://stackoverflow.com/questions/52520309/short-form-of-argparse-option-permisive-of-many-characters

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!