一个python模块,可以方便地读取和写入yaml配置文件。

yaml-configuration的Python项目详细描述


Yaml_配置

此模块为其他模块或启动提供了简单的配置 剧本。它提供了加载和保存配置文件以及读取 并向其写入配置值。同时尝试通过 如果实际配置值不是 支持present。

用法

类defaultconfig提供包的基本功能。 自定义配置类就是从它派生出来的。

importosimportloggingfrompytestimportraisesfromyaml_configuration.configimportDefaultConfig,ConfigErrordefread_file(file_path,filename):file_path=os.path.join(file_path,filename)withopen(file_path,'r')asfile_pointer:file_content=file_pointer.read()returnfile_contentclassBasicConfig(DefaultConfig):def__init__(self,config_string,config_file,logger_object=None):super(BasicConfig,self).__init__(config_string,logger_object)# this is already done in the init# self.load(config_file, path=os.path.dirname(__file__))if__name__=='__main__':config_file="basic_config.yaml"config_string=read_file(os.path.dirname(__file__),config_file)basic_config=BasicConfig(config_string,config_file,logging.getLogger("TestLogger"))basic_config.set_config_value("number_value",10)basic_config.set_config_value("string_value","test_string")assertbasic_config.get_config_value("string_value")=="test_string"assertbasic_config.get_config_value("not_existing_config_value",default=42)==42withraises(ConfigError):ifnotbasic_config.get_config_value("value_that_should_exist"):raiseConfigError("The config value with key 'value_that_should_exist' should exist")

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

推荐PyPI第三方库


热门话题
在扩展类中将Java重写为抽象的非抽象方法   java可滚动视图   java Android:隐藏操作栏,保持标签   java如何在Hibernate中使用@Qualifier   java如何在spring MVC中进行Http会话管理以获取数据库中的数据   java如何为TictaToe游戏创建HashMap   java在消息资源文件中查找未使用的值   从源代码构建Kafka时发生java错误   c中的java调用optaplanner DLL#   无法通过Java API访问orientdb函数   任务的java执行失败“:app:ProcessDebuggGoogleService”   java在整个模拟过程中保持代理之间的距离不变   如何在Java中使用BouncyCastle PGP实用程序实现增量加密?   java在安卓中计算画布点的距离   Java回文修订   java在Firebase数据库中存储变量的必要性   java如何使用gquery手势插件在页面上启用文本突出显示?   java如何在Apache camel中使用POST调用REST?