2024-04-19 23:47:46 发布
网友
我不确定optparse的metavar参数用于什么。我看到它到处都在使用,但我看不到它的用途。
optparse
metavar
有人能跟我说清楚吗?谢谢。
正如@Guillaume所说,它用于生成帮助。如果希望有接受参数的选项(如文件名),可以将metavar参数添加到add_option调用中,以便在帮助消息中输出首选参数名称/描述符。来自the current module documentation:
add_option
usage = "usage: %prog [options] arg1 arg2" parser = OptionParser(usage=usage) parser.add_option("-f", "--filename", metavar="FILE", help="write output to FILE"),
会产生这样的帮助:
usage: <yourscript> [options] arg1 arg2 options: -f FILE, --filename=FILE
“-f”和“--filename”后面的“文件”来自metavar。
metavar似乎用于生成帮助:http://www.python.org/doc/2.5.2/lib/optparse-generating-help.html
metavar是用于在screen after选项中打印的变量。通常用于建议输入的选项是用户的FILE或INT或STRING。没有metavar,optparse将在添加选项后打印dest值。
FILE
INT
STRING
dest
正如@Guillaume所说,它用于生成帮助。如果希望有接受参数的选项(如文件名),可以将
metavar
参数添加到add_option
调用中,以便在帮助消息中输出首选参数名称/描述符。来自the current module documentation:会产生这样的帮助:
“-f”和“--filename”后面的“文件”来自metavar。
metavar似乎用于生成帮助:http://www.python.org/doc/2.5.2/lib/optparse-generating-help.html
metavar
是用于在screen after选项中打印的变量。通常用于建议输入的选项是用户的FILE
或INT
或STRING
。没有metavar
,optparse
将在添加选项后打印dest
值。相关问题 更多 >
编程相关推荐