Python 2.6, File read() problems in Windows Xp

Dave Angel davea at ieee.org
Fri May 8 09:25:56 CEST 2009


Li Wang wrote:
> Hi all:
>
> I am trying to read a non-text file as a string by using Python
> read(), however, it seems there is some thing wrong with it. I can use
> read() on text file correctly, but unable to read .xls file correctly.
> (The program can read any file correctly in Fedora 10)
>
> Any idea how to solve this problem?
>
> Thank you very much!
>
>   
Chances are you forgot the "b" parameter to open().  Unnecessary in 
Unix, it tells the library to *not* translate \r\n  to \n upon read, or 
the inverse on write.  In other words, with the "b" parameter, the file 
is read in unchanged.

        infile = open(filename, "rb")
       ....





More information about the Python-list mailing list