Characters Being Misread

Michiel Overtoom motoom at xs4all.nl
Tue Jul 15 10:15:39 EDT 2008


Victor wrote...

>>>> import binascii
>>>> binascii.unhexlify('\x0c')
>TypeError: Odd-length string
>What gives here?

The function unhexlify() wants an even-length string. From the online help:

>>> help(binascii.unhexlify)
unhexlify(...)
    a2b_hex(hexstr) -> s; Binary data of hexadecimal representation.    
    hexstr must contain an even number of hex digits (upper or lower case).
    This function is also available as "unhexlify()"

And you use it like this:

>>> binascii.unhexlify("41")
'A'


You feed it data without any '0x' prefixes.

What are you trying to do? Parsing an RTF file which contains unicode
characerts, encoded as hexadecimal?

Greetings,


-- 
"The ability of the OSS process to collect and harness
the collective IQ of thousands of individuals across
the Internet is simply amazing." - Vinod Vallopillil
http://www.catb.org/~esr/halloween/halloween4.html




More information about the Python-list mailing list