[Tutor] How to convert hex representation of char? (Challenge part 8)

plust pieter.lust at katho.be
Thu May 19 13:20:58 CEST 2005


Kent Johnson wrote:
<snip>
> One way is to paste the string into a program; when Python sees '\x14' it creates a string of length 1:
> 
>   >>> len('\x14')
> 1
> 
> Alternately you can use the 'string_escape' codec to convert the string:
>   >>> s=r'\x14'
>   >>> len(s)
> 4
>   >>> t=s.decode('string_escape')
>   >>> t
> '\x14'
>   >>> len(t)
> 1
> 
> Kent
> 

Thanks! That solves my problem.

Pieter Lust.



More information about the Tutor mailing list