Determine file type (binary or text)

Peter Hansen peter at engcorp.com
Wed Aug 13 16:39:46 CEST 2003


Sami Viitanen wrote:
> 
> How can I check if a file is binary or text?
> 
> There was some easy way but I forgot it..

First you need to define what you mean by binary and text.
Is a file "text" simply because it contains only the
printable (in ASCII) bytes between 31 and 127, plus 
CR and/or LF, or do you have a more complex definition 
in mind.

Better yet, what do you need the information for?  Maybe
the answer to that will show us the proper path to take.




More information about the Python-list mailing list