Newbie - converting binary data to ASCII text ?

Peter I. Hansen pih at
Sun Oct 14 01:02:19 CEST 2001

Cyr wrote:

> hello,
> I'm completely new to python and I've got problem reading binary data file.
> When I read a file with read(), the binary data aren't converted. In fact,
> I'd like to know if there's a method for converting a file object (or a
> string) from binary to the equivalent ASCII text. The data aren't written in
> a particular format. Fortran doesn't have any problem with theese files
> I'would greetly appreciate any help, thanks
> Cyril D
> PS : I'm working on an SGI Irix operating system

Try something like :

from array import array
A = array('d') # 'd' for double
file = open("filename",'rb') # 'rb' read binary
A.fromfile(file,N) # N is the number of bytes you want to read
print A # To view the array :)


More information about the Python-list mailing list