[Tutor] How to make the difference between binary and text files ?

Kent Johnson kent37 at tds.net
Sun Apr 5 02:02:38 CEST 2009


On Sat, Apr 4, 2009 at 7:07 AM, Dominique <mydomdom at gmail.com> wrote:
> Hello,
>
> 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.
> Consequently, before opening the file, I'd like to test it to adapt the opening
> mode ('r' or 'rb').
>
> Is there a way to make the difference between binary and text files ?

You might want to look at grin which has full-featured recursive
search including identifying binary files:
http://pypi.python.org/pypi/grin

Kent


More information about the Tutor mailing list