can python read .ini file like php Yaconf -
this question has answer here:
- how read , write ini file python3? 5 answers
php yaconf can read .ini file
a=123 b=45 c.e.f=987
output like
['a' => 123] ['b' => 45] ['c' =>['e'=>['f'=>987]]]
can python read this?
thx
hi, all, may did not describe question well, sorry that
firstly, did tried configparser, parse config key=value
. have config a.b.c=value
, e.g:
[cache] redis.master.host='10.10.10.10' redis.master.port='6379' redis.master.auth='xxxx' redis.slave_1.host='10.10.10.12' redis.slave_1.port='6389' redis.slave_1.auth='xxxx'
so, read config like
cfger.get('cache', 'redis')
and hope result
{'redis': { 'master': { 'host': '10.10.10.10', 'port': '6379', 'auth': 'xxxx', }, 'slave_1': { 'host': '10.10.10.12', 'port': '6389', 'auth': 'xxxx', }, } }
hope can know said
yes possible. not go deep. use belove snippet boilerplate.
$ cat some.ini a=123 b=45 c.e.f=987 ... >>>h = {} >>>l = [] >>> open('some.ini') inifile: ... lines in inifile.readlines(): ... k,v = lines.split('=') ... h[k] = int(v) ... # or l.append([lines.strip()]) >>> h {'a': 123, 'c.e.f': 987, 'b': 45}
the thing have is, parse 'c.e.f' nested dict.
Comments
Post a Comment