Determine file type (binary or text)

bromden bromden at gazeta.pl.no.spam
Wed Aug 13 13:03:15 CEST 2003


>  >>> f = os.popen('file -bi test.py', 'r')
>  >>> f.read().startswith('text')

sorry, it's not general, since "file -i" returns
"application/x-shellscript" for shell scripts,
it's better to go like that:
 >>> import os
 >>> f = os.popen('file test.py', 'r')
 >>> f.read().find('text') != -1

-- 
bromden[at]gazeta.pl





More information about the Python-list mailing list