Determine file type (binary or text)

bromden bromden at gazeta.pl.no.spam
Wed Aug 13 06:50:45 EDT 2003


> 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