python中的getopt怎么理解
2018-01-22 16:50
337 查看
在看crfascnn代码的demo时看到这个语句,上网查了一下,可以参考这个博文:
http://blog.csdn.net/chengxuyuanyonghu/article/details/42556885
demo中相关的代码以及我的解释如下:
try:
opts, args = getopt.getopt(argv, 'hi:o:g:', ["ifile=", "ofile=", "gpu="]) # argy为运行程序时自己添加的参数,如运行程序:python crfasrnn_demo.py -i my_pic.jpg -o my_out.png -g -1 即可指定自己的图片为my_pic.jpg,输出my_out.png
except getopt.GetoptError:
print("crfasrnn_demo.py -i <input_file> -o <output_file> -g <gpu_device>")
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
print("crfasrnn_demo.py -i <inputfile> -o <outputfile> -g <gpu_device>")
sys.exit()
elif opt in ("-i", "ifile"): #若指定了ifile的参数,更新input_file
input_file = arg
elif opt in ("-o", "ofile"): #若指定了ofile的参数,更新output_file
output_file = arg
elif opt in ("-g", "gpudevice"):
gpu_device = int(arg)
http://blog.csdn.net/chengxuyuanyonghu/article/details/42556885
demo中相关的代码以及我的解释如下:
try:
opts, args = getopt.getopt(argv, 'hi:o:g:', ["ifile=", "ofile=", "gpu="]) # argy为运行程序时自己添加的参数,如运行程序:python crfasrnn_demo.py -i my_pic.jpg -o my_out.png -g -1 即可指定自己的图片为my_pic.jpg,输出my_out.png
except getopt.GetoptError:
print("crfasrnn_demo.py -i <input_file> -o <output_file> -g <gpu_device>")
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
print("crfasrnn_demo.py -i <inputfile> -o <outputfile> -g <gpu_device>")
sys.exit()
elif opt in ("-i", "ifile"): #若指定了ifile的参数,更新input_file
input_file = arg
elif opt in ("-o", "ofile"): #若指定了ofile的参数,更新output_file
output_file = arg
elif opt in ("-g", "gpudevice"):
gpu_device = int(arg)
相关文章推荐
- Python私有方法不能外部调用怎么理解?
- 想了解python的urllib2是怎么实现的,可以看pypy版本便于理解
- python面向对象中的__init__方法怎么理解?
- python中yield关键字怎么理解?
- pip装了一个包,但是python里Import的时候找不到怎么办?
- 同时装了Python3和Python2,怎么用pip?
- CGAffineTransform这个结构体到底怎么理解? 每个值都标示什么含义呢?
- 对Python中文分词模块结巴分词算法过程的理解和分析
- Python资料之getopt模块
- 对Python装饰器的个人理解
- 传说中Python最难理解的点|看这完篇就够了(装饰器)
- "if not rs.eof and not rs.bof then"怎么理解?见asp实例
- 怎么理解什么是大数据呢?
- 深入理解Python中的字符编码、文件处理和函数
- python爬虫怎么赚钱?学完Python能做什么?
- 理解python并发编程-进程篇
- Python 之小白的系统进程的理解之进程池Pool
- Python中,怎么在字符串里嵌入双引号或者单引号
- 怎么理解面向对象和面向过程到底的本质区别? .
- 理解Python的函数