库和应用程序的配置标志。
oscar.flag的Python项目详细描述
oscar.flag提供可扩展的命名空间标志,这些标志可以是 从环境变量、命令行参数和配置中分析 文件夹。
在应用程序或库中使用标志的位置声明标志, 它们通过与其完全匹配的命名空间访问 限定模块路径。
文档位于Read the Docs,代码位于GitHub。
示例
应用程序入口点:
import sys from oscar import flag import other_module FLAGS = flag.namespace(__name__) FLAGS.some_int = flag.Int('some integer value', default=1) if __name__ == '__main__': flag.parse_commandline(sys.argv[1:]) flag.die_on_missing_required() print 'other_module.multiply_by(%d) = %d' % ( FLAGS.some_int, other_module.multiply_by(FLAGS.some_int))
其他模块.py:
from oscar import flag FLAGS = flag.namespace(__name__) FLAGS.multiplier = flag.Int('some integer', default=flag.REQUIRED) def multiply_by(i): return i * FLAGS.multiplier
外壳:
$ python example.py Missing required flags: [other_module.]multiplier Usage of example.py: __main__: [__main__.]some_int=None: some integer value other_module: [other_module.]multiplier=<required>: some integer # Note the namespaced reference --other_module.multiplier. $ python example.py --other_module.multiplier=2 --some_int=3 other_module.multiply_by(3) = 6