binary or ascii

Ralph Corderoy ralph at inputplus.demon.co.uk
Tue Aug 29 11:55:03 EDT 2000


Hi,

> Is there a way (function or trick) to determine whether a given file
> is in ASCII or binary format?

Here's an extract from the perlfunc(1) man page on its -T operator.

    The -T and -B switches work as follows.  The first block or so of
    the file is examined for odd characters such as strange control
    codes or characters with the high bit set.  If too many odd
    characters (>30%) are found, it's a -B file, otherwise it's a -T
    file.  Also, any file containing null in the first block is
    considered a binary file.

So that's one method.  IIRC the implementation didn't match the
documentation at one point.


Ralph.




More information about the Python-list mailing list