Detecting Binary content in files

Benjamin Kaplan benjamin.kaplan at
Tue Mar 31 19:06:05 CEST 2009

On Tue, Mar 31, 2009 at 12:23 PM, ritu <ritu_bhandari27 at> wrote:

> Hi,
> I'm wondering if Python has a utility to detect binary content in
> files? Or if anyone has any ideas on how that can be accomplished? I
> haven't been able to find any useful information to accomplish this
> (my other option is to fire off a perl script from within m python
> script that will tell me whether the file is binary), so any pointers
> will be appreciated.

All files are binary. The question is whether every byte in the file
represents a (whole or part of a) character or whether some of the data
represents a different data type. You could theoretically have a "binary"
file that appears in a text editor to be perfect English. How does your perl
script tell the difference?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Python-list mailing list