Characters Being Misread

Michiel Overtoom motoom at
Tue Jul 15 16:15:39 CEST 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)
    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")

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?


"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

More information about the Python-list mailing list