determining file type
maric at aristote.info
Wed Jun 14 11:53:29 CEST 2006
Le Mercredi 14 Juin 2006 11:22, Ritesh Raj Sarraf a écrit :
> I have a funtion named unzipper() which does the work of unzipping the
> Is there a way I can identify what is the type of the file which'll be
> passed to unzipper().
> If yes, I'll be able to make out if it's a zip file or a tar or a bz2
Under Linux you can use the file command in a pipe.
In all cases, you use the "magic" repository of the file command directly like
this (I found the '\xff\xd8' for jpeg in /usr/share/file/magic.mime on my
In : f = file ('samurai_tux.jpg')
In : s = f.read(2)
In : s == '\xff\xd8'
Aristote - www.aristote.info
3 place des tapis
Tel: +33 426 880 097
More information about the Python-list