guess file type in python

GiBo gibo at gentlemail.com
Wed Feb 21 21:46:51 EST 2007


mark wrote:
> Is there any way to guess the file type using python?
> thanks
> mark
> 
> For example in unix:
> 
> file code.py
> code.py: a python script text executable
> 
> file Eccentric.gif
> Eccentric.gif: GIF image data, version 89a, 237 x 277

"file" tool uses libmagic.so library which in turn uses /etc/magic file
with file format descriptions. To get some reliable results you'll have
to call libmagic. The "file-4.xx.tar.gz" source tarball has python
bindings included and there's a python-magic package (at least in
Debian) that provides libmagic bindings for python.

HTH,

GiBo






More information about the Python-list mailing list