How to convert binary file data?

DOC doc at sympatico.ca
Tue May 8 23:46:47 EDT 2001


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
'\xe0'

>>># try the eval
...eval (buf)
Traceback...
...
SyntaxError: unexpected EOF while parsing

>>># OK try string.atoi!
...string.atoi (buf)
Traceback...
...
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?

Thanks,
DOC






More information about the Python-list mailing list