python - ConfigParser and String interpolation with env variable -
it's little bit i'm out of python syntax , have problem in reading .ini
file interpolated values.
this ini file:
[default] home=$home test_home=$home [test] test_1=$test_home/foo.csv test_2=$test_home/bar.csv
those lines
from configparser import safeconfigparser parser = safeconfigparser() parser.read('config.ini') print parser.get('test', 'test_1')
does output
$test_home/foo.csv
while i'm expecting
/users/nkint/foo.csv
edit: i supposed $
syntax implicitly included in called string interpolation (referring manual):
on top of core functionality, safeconfigparser supports interpolation. means values can contain format strings refer other values in same section, or values in special default section.
but i'm wrong. how handle case?
first of according documentation should utilize %(test_home)s
interpolate test_home
. key case insensitive , can't utilize both home
, home
keys. can utilize safeconfigparser(os.environ)
take in business relationship of environment.
from configparser import safeconfigparser import os parser = safeconfigparser(os.environ) parser.read('config.ini')
where config.ini
is
[default] test_home=%(home)s [test] test_1=%(test_home)s/foo.csv test_2=%(test_home)s/bar.csv
python configparser
No comments:
Post a Comment