这是一个 Python 配置快速注册调用模块,主要解决多维数组深层次配置调用问题。
pip install config-registry
from ConfigRegistry import ConfigRegistry
setting = Registry()
setting.set('a', 'a')
setting.set('b', {'bb': 'bbb'})
setting.set('c.h', 'h')
print(setting.get())
print(setting.get('b.bb'))
from ConfigRegistry import ConfigRegistry
setting = ConfigRegistry()
setting.load({'a': {'aa': 'aaa'}})
print(setting.get('a.aa'))
from ConfigRegistry import ConfigRegistry
setting = ConfigRegistry()
setting.load({'a': {'a1': 'aaa1'}})
setting.merge('a', {'a2': 'aaa2' })
print(setting.get('a'))
from ConfigRegistry import ConfigRegistry
setting = ConfigRegistry()
setting.set('a', 'aaa')
setting.default('a', 'bbb')
setting.default('c', 'ccc')
print(setting.get('a'))
print(setting.get('c'))
import time
from ConfigRegistry import ConfigRegistry
setting = ConfigRegistry()
def callback():
print('callback')
setting.set_hook('hook', 3, callback)
time.sleep(1)
setting.refresh_hook('hook')
time.sleep(3)
setting.refresh_hook('hook')
from ConfigRegistry import ConfigRegistry
setting = ConfigRegistry({'a': {'aa': 'aaa'}, 'b': {'bb': 'bbb'}})
print(setting.flat())