python - ConfigParser and String interpolation with env variable -


It is a little bit that I'm out of the Python syntax and I have a problem reading Iini File interpolated values ​​with

This is my INI file:

  [default] home = $ HOME test_home = $ home [test] test_1 = $ test_home / foo .csv test_2 = $ test_home / Bar.csv  

Import from those rows

  Secure Configure Parser = Safe Configurator () parser with ConfigParser Reid ('config.ini)  
  $ test_home / foo.csv  

ago>

I hope when

  / user / nkint / foo.csv  

edit:

I'm assuming the $ syntax Inherently included in the so-called string projection (referred to as the):

On top of the main functionality, SafeConfigParser supports projection The value in that value can be string strings, which Refers to other values ​​in the same section, or values ​​in a special default section.

But how am I supposed to handle this issue?

< P>

According to the document, first you % (% Test_home) << code> test_home to interpelt In addition, the key case is insensitive and you can not use both the HOME and home keys. Finally you can SafeConfigParser (os.environ) Use environment About can take into consideration.

Import from ConfigParser SafeConfigParser import os parser = SafeConfigParser (os.environ) parser .read ('config.ini')

Where < Code> config.ini is

  [default] test_home =% (HOME)) S [test] test_1 =% (test_home) s / foo.csv test_2 =% (test_home) ) S / bar.csv  

Comments