hex value in string back to real hex value

jack jacques.coeurs at laposte.net
Wed Sep 8 03:11:51 EDT 2004


Thanks,

The solution provided by phil and peter works perfectly for my
solution (and I will have to work a little more to understand them
fully). I will check the binascii.

Regards.
Jack.

Phil and peter

Peter Otten <__peter__ at web.de> wrote in message news:<chks4h$o8r$01$1 at news.t-online.com>...
> jack wrote:
> 
> > I get in a program an hexa value codes in a string for example \xe7
> > which correspond to a french character.
> > 
> > The string would be "\xe7t\xe7" and I want to write in a file été and
> > not \xe7t\xe7.
>  
> "\xe7t\xe7" _is_ the same as "été" if you are using e. g. the ISO-8859-1
> encoding, so chances are you will see été if you open the file in a text
> editor without the need of prior conversions.
> 
> But I may be misunderstanding you and you really have "\\xe7t\\xe7" - in
> that case you can use de/encode to switch between the two representations:
> 
> >>> "été".encode("string_escape")
>  '\\xe9t\\xe9'
> >>> _.decode("string_escape")
>  '\xe9t\xe9'
> >>> print _
> été
> 
> (In the interpreter the result of the previous calculation is assigned to _
> if it is not None)
> 
> Peter



More information about the Python-list mailing list