Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/328.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用argparse显示脚本的功能_Python_Argparse - Fatal编程技术网

Python 使用argparse显示脚本的功能

Python 使用argparse显示脚本的功能,python,argparse,Python,Argparse,当我用-h调用我的脚本时,我希望它打印一条消息,告诉我“这个脚本确实如此” 我的意思是当我 $myscript --help 它应该显示 This script is used to fire monkeys and hire donkeys. usage -- .... 只需向每个参数添加help=“my help message”。 回答我自己的问题: 我需要使用 parser = argparse.ArgumentParser(description="This script ...

当我用-h调用我的脚本时,我希望它打印一条消息,告诉我“这个脚本确实如此”

我的意思是当我

$myscript --help
它应该显示

This script is used to fire monkeys and hire donkeys.

usage -- ....
只需向每个参数添加help=“my help message”。
回答我自己的问题:

我需要使用

parser = argparse.ArgumentParser(description="This script ... "

我可以将一个字符串传递给ArgumentParser,但它会在“用法”之后打印该消息。请回答您的问题以添加更多信息。你能举例说明你现在看到的以及你希望它看起来怎么样吗?您的问题非常不清楚。如果您想在选项列表后添加一些文本,请使用
epilog=“但是,请稍候,在您设置的同一函数
description=
中还有更多”