如何避免 python 的 argparse 模块中的大写占位符? [英] How do I avoid the capital placeholders in python's argparse module?
本文介绍了如何避免 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
如果我尝试使用空元变量字符串:
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屋!
查看全文