Can you display that file on an editor? Are you sure you don't have a binary file? In that case use 'rb'
Using the python shell makes things look messy.
bumsfeld
Nearly a Posting Virtuoso
1,445 posts since Jul 2005
Reputation Points: 404
Solved Threads: 184
Actually using the Python Shell in this case gave the clue that this was not a text file, since most of the ASCII text characters are less than hex A0.
vegaseat
DaniWeb's Hypocrite
5,989 posts since Oct 2004
Reputation Points: 1,345
Solved Threads: 1,417
try f.readlines() instead of f.read()
f.read() is basically doing it's job, reading one line at a time. With readlines() though, the whole thing becomes an object that you can then iterate through or search etc.
i think the online python manual also has some example differences.
hope that helps
sf2k
Some basics:
read() reads to EOF, or if opened as a binary, to the last byte
read(n) reads n bytes
readline() reads a line at a time, the line ends with '\n' or EOF.
readlines() uses readline() to read all the lines in a file and returns a list of lines.
The first three functions return a string object, the last function returns a list object. EOF is a special character used as End Of File marker.
vegaseat
DaniWeb's Hypocrite
5,989 posts since Oct 2004
Reputation Points: 1,345
Solved Threads: 1,417