A question regd configobj

Dave Angel davea at ieee.org
Thu May 21 21:06:50 CEST 2009


Srijayanth Sridhar wrote:
> Hello,
>
> 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'
>
> As you can see the string has escaped the '\' and I want to suppress that
> behavior. I've looked at the documentation and haven't been able to figure
> out if this is an available feature or not.
>
> Any help will be greatly appreciated.
>
> Thank you,
>
> Jayanth
>
>   
When you are using the Python interpreter, the interpreter will escape 
the strings it displays, if you use your present approach.  Try using 
print() to see what the string really contains.

Both approaches are useful -- the interpreter tries to show you 
approximately what you'd have to type to create that value.  Print just 
displays the character, allowing them to take whatever action is called 
for on the output device.

 >>> st = "Line 1\nLine 2"
 >>> st
'Line 1\nLine 2'
 >>> print st
Line 1
Line 2
 >>>




More information about the Python-list mailing list