配置库(Hocon格式)
简介:Hocon是Json和Properties的超集,可以完全兼容两种格式
C Sharp下的实现
https://www.cnblogs.com/sunjie9606/p/5163302.html
https://github.com/akkadotnet/HOCON
Python支持
https://github.com/chimpler/pyhocon
Java支持
https://lightbend.github.io/config/
使用方法
from pyhocon import ConfigFactory
conf = ConfigFactory.parse_file('samples/database.conf')
host = conf.get_string('databases.mysql.host')
same_host = conf.get('databases.mysql.host')
same_host = conf['databases.mysql.host']
same_host = conf['databases']['mysql.host']
port = conf['databases.mysql.port']
username = conf['databases']['mysql']['username']
password = conf.get_config('databases')['mysql.password']
password = conf.get('databases.mysql.password', 'default_password') #找不到key使用默认值