[Tutor] How to make the difference between binary and text files ?
orsenthil at gmail.com
Sat Apr 4 14:12:41 CEST 2009
On Sat, Apr 4, 2009 at 6:07 AM, Dominique <mydomdom at gmail.com> wrote:
> I am developing a very small multi-platform app to search for a specific word or
> expression in files located in a drive or directory.
> So I need to open files to search for the word.
> I read that opening a binary file as a text file (open(filename, 'r')) may
> corrupt the file.
First of all, I doubt if reading a file in text format would cause any harm.
Writing may screw things up.
Secondly, determining the type of file is based on heuristics and most
often determined by reading a chunck of the file. I found the
following recipe, that could be useful to you:
More information about the Tutor