0
import getopt
options, remainder = getopt.getopt(sys.argv[1:], 'd:a', ['directory=',
'algorithm',
'version=',
])
print 'OPTIONS :', options
for opt, arg in options:
if opt in ('-d', '--dir'):
directory_path = arg
elif opt in ('-a', '--alg'):
algorithm = arg
elif opt == '--version':
version = arg
这个脚本工作正常,但如果用户没有指定任何参数(-d选项是必须的),我怎么指定这使程序继续而不会退出并显示错误:因为没有指定文件路径
如果用户不知道哪些参数可用,我该如何显示帮助或用法?
等一下。你自己解析选项? –