要跨模块使用的全局configparser对象

klang-globconf的Python项目详细描述


Build status

全局配置

创建全局configparser对象,而不考虑需要它的项目和模块

开始

在项目中:

from globconf import config
# config will attempt to read local config.ini file if present - otherwise:

if 'important section' not in config.sections():
    config.read_string("""
    [important section]
    host = critical-system.com
    user = REST_USER
    pwd = REST_PASSWORD
    verify_ssl = false
    """)
# or config.read('some_other_config.ini')

# load class using globconf.config

在模块中:

from globconf import config, verify_required_options
class module(object):
    def __init__(self):
        sec = 'service now'
        self.cfg = verify_required_options(sec, ['host', 'user', 'pwd'])
        if not self.cfg.getboolean('verify_ssl', fallback=True):
            import urllib3
            urllib3.disable_warnings(InsecureRequestWarning)

只要有人在全局配置中初始化了所需的部分,您的模块就会很高兴。

先决条件

配置分析器

安装

一个循序渐进的示例系列,告诉您如何使开发环境运行

Give the example

然后重复

until finished

以从系统中获取一些数据或将其用于小演示为例结束

套餐

python setup.py sdist

测试

pytest

pyton -m unittest

作者

许可证

这个项目是在麻省理工学院的许可下授权的-详细信息请参见LICENSE.md文件

致谢

  • 向任何使用过代码的人提供帽子小费
  • 灵感

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java为什么整数构造函数方法不再需要属性?   java单函数从广播接收器检索数据   Java类中的Scala设置器和获取器   JAVA MVC表选择的行ID和mysql db ID不同   java在Multimaps Guava中获取值   jakarta ee Intellij IDEA Java类在保存时不自动编译   java在另一个Spring实体中使用Spring实体   JTwitter库的安卓类一直在给我java。朗朗:温特韦尔。杰特维特。啁啾   java停止启动应用程序   java Jersey测试NoSuchMethodError   java如何处理合成元素上的注释   java崩溃shell无法通过ssh连接   java计算两个日期之间的天数后(取自edittext)如何在新的edittext中显示天数