[BangPypers] how to Identify file type

Gora Mohanty gora at mimirtech.com
Fri Jul 15 10:55:05 CEST 2011


On Fri, Jul 15, 2011 at 2:12 PM, Sibtey Mehdi <sibtey.mehdi at gmail.com> wrote:
> Hi ,
>
> I am writing a script in python to identify the type of a file.In most of
> the cases I got the correct file type on the basis of file extension.
> Is there any way to identify a PLSQL, TSQL or SQl file as these files may
> have the same 'sql' extension.

Going by the extension is unreliable. If you are OK with running
on a Linux (probably also other UNIX systems that support libmagic),
you can use python-magic which provides bindings to libmagic:
http://pypi.python.org/pypi/python-magic/

Regards,
Gora


More information about the BangPypers mailing list