A question regd configobj

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Fri May 22 09:00:57 CEST 2009


En Thu, 21 May 2009 08:23:36 -0300, Srijayanth Sridhar  
<srijayanth at gmail.com> escribió:

> I am wondering if it is possible to have hexadecimal strings in a ini  
> file
> and have configobj parse it correctly.
>
> for eg:
> moonwolf at trantor:~/python/config$ cat foo
> foo="\x96\x97"
> .
> .
> .
>>>> a=ConfigObj("foo")
>>>> a
> ConfigObj({'foo': '\\x96\\x97'})
>>>> a['foo']
> '\\x96\\x97'

Use the "string-escape" codec to decode that:

py> x = '\\x96\\x97'
py> x.decode("string-escape")
'\x96\x97'

You can decode more-or-less automatically the whole config file, using the  
walk method. See  
http://www.voidspace.org.uk/python/configobj.html#walking-a-section (the  
example covers exactly this use case)

-- 
Gabriel Genellina




More information about the Python-list mailing list