Determine file type (binary or text)
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')
> (btw, f.read() returns 'text/x-java; charset=us-ascii\n')
More information about the Python-list