Sniffing Text Files

Mike Meyer mwm at
Fri Sep 23 16:55:55 CEST 2005

David Pratt <fairwinds at> writes:
> Thanks Mike for your reply.  I am not aware of libmagic and will look
> to see what it provides.

and ...

Skip Montanaro <skip at> writes:
> You can also run the file(1) command and see what it says.  I seem
> to recall someone asking about the equivalent to file(1) implemented in
> Python awhile back.  

libmagic is the smarts of the file command. As I said before, people
have done Python wrappers for it. It uses a text database describing
how to recognize a files type - see the magic(5) man page for details
on that. If you use libmagic, you'll probably want to provide your own
version of the databse, excerpted to include just the file types you
want to recognize.

You can check on whether or not this will work for you by seeing what
the file command says about your sample data.

Mike Meyer <mwm at>
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.

More information about the Python-list mailing list