Skip to content

Instantly share code, notes, and snippets.

@stiandre
Created January 28, 2013 11:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stiandre/4654813 to your computer and use it in GitHub Desktop.
Save stiandre/4654813 to your computer and use it in GitHub Desktop.
python-magic (libmagic python bindings)
#!/usr/bin/env python
# Install (ubuntu/debian):
# ------------------------
# apt-get install python-magic
import magic
ms = magic.open(magic.MAGIC_NONE)
ms.load()
type = ms.file("/path/to/some/file")
print type
f = file("/path/to/some/file", "r")
buffer = f.read(4096)
f.close()
type = ms.buffer(buffer)
print type
ms.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment