Determine file type (binary or text)

Sami Viitanen none at none.net
Wed Aug 13 13:17:47 CEST 2003


Works well in Unix but I'm making a script that works on both
Unix and Windows.

Win doesn't have that 'file -bi' command.

"bromden" <bromden at gazeta.pl.no.spam> wrote in message
news:bhd559$ku9$1 at absinth.dialog.net.pl...
> > How can I check if a file is binary or text?
>
>  >>> import os
>  >>> f = os.popen('file -bi test.py', 'r')
>  >>> f.read().startswith('text')
> 1
>
> (btw, f.read() returns 'text/x-java; charset=us-ascii\n')
>
> --
> bromden[at]gazeta.pl
>






More information about the Python-list mailing list