Newbie - converting binary data to ASCII text ?

Steve Holden sholden at holdenweb.com
Sat Oct 13 06:05:19 EDT 2001


"Cyr" <cd.cd at wanadoo.fr> wrote in message news:9q92g4$6hd$1 at wanadoo.fr...
> 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
>
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.

regards
 Steve
--
http://www.holdenweb.com/


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





More information about the Python-list mailing list