How to convert binary file data?
sholden at holdenweb.com
Wed May 9 04:01:10 CEST 2001
Take a look at the struct module, which was good enough for reading Outlook
Express files. Otherwise you'll need to use the ord() function to get the
character's numeric value, but that way madness lies when you already have
"DOC" <doc at sympatico.ca> wrote ...
> I must be missing something here. I am reading a file that has
> binary data and want to be able to handle/convert it...
> But I can't seem to figure out how to do it.
> >>># read in 1 byte:
> ...buf=x.read (1)
> >>># this is what's in buf
> ... buf
> >>># try the eval
> ...eval (buf)
> SyntaxError: unexpected EOF while parsing
> >>># OK try string.atoi!
> ...string.atoi (buf)
> ValueError: invalid literal for int():
> An odd char is shown for both of the above. Likely unicode for \xe0.
> So can someone tell me the right way to handle this?
More information about the Python-list