[Tutor] reading binary files
etrade.griffiths at dsl.pipex.com
etrade.griffiths at dsl.pipex.com
Mon Feb 2 12:31:40 CET 2009
Hi
I am trying to read data from a file that has format
item_name num_items item_type items ....
eg
TIME 1 0.0
DISTANCE 10 0.0 1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0
TIME 1 1.0
DISTANCE 10 1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 10.0
I can read this if the data are in ASCII format using
in_file = open("my_file.dat","r")
data1 = in_file.read()
tokens = data1.split()
and then stepping through the resulting list but the data
also appear in the same format in a binary file. I tried
converting the binary file to an ASCII file using
ifile = open("my_file.dat","rb")
ofile = open("new_file.dat","w")
base64.decode(ifile, ofile)
but that gave the error "Error: Incorrect padding". I imagine
that there is a straightforward way of doing this but haven't
found it so far. Would be grateful for any suggestions!
Thanks
Alun Griffiths
-------------------------------------------------
Visit Pipex Business: The homepage for UK Small Businesses
Go to http://www.pipex.co.uk/business-services
More information about the Tutor
mailing list