Python中使用gflags

安装命令pip install python-gflags

使用示例:

import gflags

FLAGS = gflags.FLAGS

gflags.DEFINE_string('name', 'ming', 'this is a value')
gflags.DEFINE_integer('qps', 0, 'test qps')
gflags.DEFINE_boolean('debug', False, 'whether debug')
gflags.DEFINE_float('price', 0.9, 'the price of apple')

print FLAGS.name
print FLAGS.qps
print FLAGS.debug
print FLAGS.price

gflags使用说明:

1.gflags.DEFINE_type可以定义输入参数,这里列举了常用的boolean、integer、string、float,参数的含义分别为定义名称、默认值和该参数的说明,例如例子中的name可以使用--name去赋值;

2.直接在运行的时候使用--help可以看到所有的输入参数的默认值和说明;

3.gflags.FLAGS(argv)对参数进行初始化处理;

4.调用的时候直接使用gflags.FLAGS.name去调用;

5.代码中的FLAGS=gflags.FLAGS相当于别名。

原文链接:https://blog.csdn.net/chdhust/article/details/50428114 

https://blog.csdn.net/CoderPai/article/details/80420744

原文地址:https://www.cnblogs.com/yuehouse/p/11741827.html