Detect file type from the file contents, not the file name
Possible Duplicate:
How to find the mime type of a file in python?
I want to detect the type of a file, but I don't want to look at the extension because it may be incorrect. The mimetypes
module is filename based.
Is there a standard way to peek inside the file?
尝试安装python-magic模块。
>>> mime = magic.Magic(mime=True)
>>> mime.from_file("testdata/abc.pdf")
'application/pdf'
链接地址: http://www.djcxy.com/p/46790.html
上一篇: 如何猜测在Python中的文件的类型?
下一篇: 从文件内容中检测文件类型,而不是文件名