如何避免在python的argparse模块中使用大写占位符? [英] How do I avoid the capital placeholders in python's argparse module?

查看:204
本文介绍了如何避免在python的argparse模块中使用大写占位符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个问题要问它们的来源,被接受的答案是一堆教程和源代码的链接. 对argparse python模块化行为的解释:资本占位符来自哪里?

There was a question that asked where they come from, and the accepted answer was a bunch of links to tutorials and source code. Explanation for argparse python modul behaviour: Where do the capital placeholders come from?

对我没有帮助,我想摆脱它们,或者知道它们的用途.

None of it was helpful to me, I want to either get rid of them, or know their purpose.

例如,这样的一行:

parser.add_argument('-c', '--chunksize', type=int, help='chunk size in bits')

产生这样的垃圾:

optional arguments:
  -h, --help            show this help message and exit
  -c CHUNKSIZE, --chunksize CHUNKSIZE
                        chunk size in bits

,如果我尝试使用空的metavar字符串:

and if I try with an empty metavar string:

parser.add_argument('-c', '--chunksize', metavar='', type=int, help='chunk size in bits')

逗号后面有空格:

optional arguments:
  -h, --help            show this help message and exit
  -c , --chunksize      chunk size in bits

推荐答案

parser.add_argument('-c', '--chunksize', metavar='\b', type=int, help='chunk size in bits')

似乎可以工作

这篇关于如何避免在python的argparse模块中使用大写占位符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆