gpt4 book ai didi

python - 如何在 Python 中使用 getopt/OPTARG?如果给出太多参数(9),如何转换参数?

转载 作者:IT老高 更新时间:2023-10-28 22:16:50 33 4
gpt4 key购买 nike

如何在 Python 中使用 getopt/optarg?

最佳答案

这是我如何做的一个例子,我通常使用相同的基本模板:

import sys
import getopt

try:
opts, args = getopt.getopt(sys.argv[1:], 'm:p:h', ['miner=', 'params=', 'help'])
except getopt.GetoptError:
usage()
sys.exit(2)

for opt, arg in opts:
if opt in ('-h', '--help'):
usage()
sys.exit(2)
elif opt in ('-m', '--miner'):
miner_name = arg
elif opt in ('-p', '--params'):
params = arg
else:
usage()
sys.exit(2)

我认为没有任何 9 个参数的限制。

关于python - 如何在 Python 中使用 getopt/OPTARG?如果给出太多参数(9),如何转换参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6382804/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com