action=‘store_true‘ 理解和测试 | 简记
【摘要】
store_true 是指带触发 action 时为真,不触发则为假, 即默认 False ,传参 则 设置为 Truestore_false 则与之相反
运行示例代码 test.py 如...
- store_true 是指带触发 action 时为真,不触发则为假, 即默认 False ,传参 则 设置为 True
- store_false 则与之相反
运行示例代码 test.py 如下:
import sys
import argparse
def parse_args():
parser = argparse.ArgumentParser(description='run a test ')
parser.add_argument('-t', '--threshold', type=float, default=100.0, help='blurry threshold')
parser.add_argument('-f', '--first', action='store_true', help='default False')
parser.add_argument('-s', '--second', action='store_false', help='default True')
return parser.parse_args()
if __name__ == '__main__':
assert sys.version_info >= (3, 6), sys.version_info
args = parse_args()
print(args.first)
print(args.second)
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
运行命令:
python test.py
- 1
文章来源: positive.blog.csdn.net,作者:墨理学AI,版权归原作者所有,如需转载,请联系作者。
原文链接:positive.blog.csdn.net/article/details/115864758
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)