Newbie - converting binary data to ASCII text ?

Steve Holden sholden at
Sat Oct 13 12:05:19 CEST 2001

"Cyr" < at> wrote in message news:9q92g4$6hd$1 at
> hello,
> I'm completely new to python and I've got problem reading binary data
> 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
> a particular format. Fortran doesn't have any problem with theese files
Unfortunately, Python offers much greater flexibility than Python in data
handling, and correspondingly more chances to shoot yourself in the foot.
I'm assuming it's *convenient* to have these data in binary form, otherwise
you could always write  a Fortran program to convert them into something
Python finds easier to deal with ...

I also presume it was written with FORMAT statements (sheesh, does Fortran
even USE those now, showing my age I'm afraid). Python can read a particular
number of bytes if you give read() a numeric argument, but if you don't it
just tries to gobble the whole file in a oner.

Otherwise you may have to look at the struct module, and that's too tricky
for a beginner.


> PS : I'm working on an SGI Irix operating system

More information about the Python-list mailing list