Hexadecimal list conversion

Paul Hankin paul.hankin at gmail.com
Thu Dec 20 07:45:52 EST 2007


On Dec 20, 12:30 pm, Neil Webster <nswebs... at gmail.com> wrote:
> Hi All.
>
> I have a list which is a line from a file:
> ['\x003\x008\x001\x004\x007\x005\x00.\x005\x000\x002\x005\x009\x009\x00',
> '\x002\x001\x003\x006\x002\x002\x00.\x001\x007\x004\x002\x008\x002\x00']
>
> This should be in the format:
> ['381475.502599', '213622.174282']
>
> I've tried a few options using replace (replacing "\x00" with "") and
> trying to convert from hexademical to decimal.
>
> But nothing has worked.  Can anybody give any tips to help?

Is your file utf-16 (that would explain why your file has \x00 in
between every character)? If so, use codecs.open to read it, and you
won't get the \x00's (you'll get a unicode string).

Or you can remove them using replace:

a = a.replace('\x00', '')

HTH
--
Paul Hankin



More information about the Python-list mailing list