一个简单的轻量级类,允许用户回退默认值
dfault的Python项目详细描述
一个简单的轻量级类,允许用户在默认情况下回退 值
安装
pip3 install --user dfault
用法
基本示例
fromdfault.objectsimportDfaultexpected_values={"search_engine":"duckduckgo","website":"http://www.duckduckgo.com"}d=Dfault(expected_values)d.get("search_engine","google")# returns "duckduckgo" as the value existsd.get("favourite_team","leafs")# returns "leafs" as there are no values for "favourite_team"
配置
importconfigparserfromdfault.objectsimportDfaultconfig=configparser.ConfigParser()# .config:# [USER]# team=leafs#config.read(".config")default_config=config["user"]d=Dfault(default_config)d.get("team","raptors")# returns "leafs" as the value exiss in the configd.get("username","joeyism")# returns "joeyism" as there is no "username" value in the config file
版本
- 1.0.x
- 错误修复
- 1.0.0
- 首次发布