具有嵌套访问、插值和回退功能的字典。它主要用于存储程序的配置。

confdict的Python项目详细描述


confdict

通过递归访问、自引用和回退功能扩展内置python dict的配置字典。目前还没有大量的文档,您可以查看测试以了解所有特性。

示例用法。

>>>fromconfdictimportConfDict>>>cd=ConfDict(# Configuration of ConfDict, these are default values__separator='/',__self_key='.',__parent_key='..',__root_key='...',__key_key='<key>',__interpolation_regex=r'({{([^{}]*)}})',__fallback_key='fallback',# Remaining arguments will directly be stored in underlying dictusers={# fallback dict is used when a key is not found at that level'fallback':{# <key> is evaluated to key of the current level# it is useful when used with fallback'username':'{{<key>}}',# you can use self references'ssh_private_key':'/home/{{username}}/.ssh/id_rsa',},})>>>cdConfDict{'users':{'fallback':{'ssh_private_key':'/home/{{username}}/.ssh/id_rsa','username':'{{<key>}}'}}}>>>cd['users/john/username']'john'>>>cd['users/john/ssh_private_key']'/home/john/.ssh/id_rsa'>>>cd['users/john']ConfDict{'ssh_private_key':'/home/john/.ssh/id_rsa','username':'john'}>>>cd['users/jean']ConfDict{'ssh_private_key':'/home/jean/.ssh/id_rsa','username':'jean'}>>>cd['users/jean']={'username':'jeans_custom_username'}>>>cd['users/jean/ssh_private_key']'/home/jeans_custom_username/.ssh/id_rsa'>>># 'jean' exists now under 'users'>>># there is no partial fallback so there is no 'ssh_private_key'>>>cd['users/jean']ConfDict{'username':'jeans_custom_username'}>>># we can realize fallback as jean to make concrete values>>>cd['users/fallback'].realize('jean')>>>cd['users/jean']ConfDict{'ssh_private_key':'/home/jeans_custom_username/.ssh/id_rsa','username':'jeans_custom_username'}>>># interpolation still works>>>cd['users/jean/username']='jeans_custom_username2'>>>cd['users/jean/ssh_private_key']'/home/jeans_custom_username2/.ssh/id_rsa'

安装

$ pip install confdict

开发

有一个Makefile来自动执行常用的开发任务。

环境设置

### create a virtualenv for development

$ sudo pip install virtualenv # or your preferred way to install virtualenv

$ make virtualenv # will also install dependencies

$ source env/bin/activate

### run pytest / coverage

$ make test

### before commit

$ make format

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

推荐PyPI第三方库


热门话题
java无法设置@Async方法   在Java中设置链表   未设置id时遇到java StaleObjectStateException   java如何保存程序的状态并加载它?   java映射类和schemaderived类之间有什么区别?   控制器类中的java全局变量在最新会话打开时被覆盖   java Hystrix和连接池   java Sonar在我不关闭ignite对象时引发拦截器问题   java无法在Junit TestCase中为控制器设置Mockito值   java保证异步传递消息   java如何高亮显示按钮,直到为微调器提供有效值?   java在Android中使用ImageView控件创建错误   JMX垃圾收集和系统之间的java差异。gc()?   java在尝试向标记添加信息窗口时卡住了?   java JavaFX检测与后台的冲突   java将光标放在按钮上时更改按钮的位置   java Maven。如何从paren pom继承配置文件。xml?   带空格的Java填充字符串   java将两个对象设置为相等,并找到其布尔结果