$ cat format.conf

[DEFAULT]

conn_str = %(dbn)s://%(user)s:%(pw)s@%(host)s:%(port)s/%(db)s

dbn = mysql

user = root

host=localhost

port = 3306

[db1]

user = aaa

pw=ppp

db=example

[db2]

host=192.168.0.110

pw=www

db=example

 

print conf.get('db1', 'conn_str')

print conf.get('db2', 'conn_str')

这样就可以很方便的得到 db1和db2的连接串

posted on 2018-03-21 19:30  John Liang  阅读(155)  评论(0编辑  收藏  举报