Python version of perl's "if (-T ..)" and "if (-B ...)"?

Aahz aahz at
Fri Feb 12 15:26:51 CET 2010

In article <mailman.2434.1265983307.28905.python-list at>,
Lloyd Zusman  <ljz at> wrote:
>Perl has the following constructs to check whether a file is considered
>to contain "text" or "binary" data:
>if (-T $filename) { print "file contains 'text' characters\n"; }
>if (-B $filename) { print "file contains 'binary' characters\n"; }

Assuming you're on a Unix-like system or can install Cygwin, the
standard response is to use the "file" command.  It's *much* more
Aahz (aahz at           <*>

"At Resolver we've found it useful to short-circuit any doubt and just        
refer to comments in code as 'lies'. :-)"

More information about the Python-list mailing list