安裝命令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