|
From: kat k. <dok...@gm...> - 2009-03-07 06:30:30
|
Hello All,
I need to retrieve a value of a key in the configuration file as a raw
string but somehow after ConfigObj reads it, it is escaping special
characters. For e.g, here is my configuration file:
[ "constants" ]
'target_dir' = r"C:\tmpdir"
As you see above I have declared "target_dir" key's value to be a raw string
which should be evaluated literally, that is the backslash present in the
value should not be escaped.
I am reading the file like this:
>>> from configobj import ConfigObj
>>> config = ConfigObj("tmp.cfg")
>>> dir = config['constants']['target_dir']
>>> dir
'C:\\tmpdir'
although this is OK:
>>> print dir
'C:\tmpdir'
but when we do print, the string is evaluated.
If you see, the backslash gets escaped and I no longer get the raw string I
had in my configuration file.
What should I do so that ConfigObj reads that value as a raw string and give
me r"C:\tmpdir" instead of "C:\\tmpdir"
Thanks much for your help
-kk
|