python-magic 识别文件类型
python-magic简介
python-magic,Python的第三方库。python-magic是指向libmagic文件类型标识库的python接口。而libmagic则是通过预定义的文件类型列表检查文件头从而来识别文件的相关类型。
python-magic应用实例
>>> import magic
>>> magic.from_file("testdata/test.pdf")
'PDF document, version 1.2'
# recommend using at least the first 2048 bytes, as less can produce incorrect identification
>>> magic.from_buffer(open("testdata/test.pdf", "rb").read(2048))
'PDF document, version 1.2'
>>> magic.from_file("testdata/test.pdf", mime=True)
'application/pdf'
python-magic Github统计数据
The MIT License (MIT)
Github 2.4k stars
python-magic安装命令
pip install python-magic
Python版本要求
python-magic 0.4.27 Requires: Python >=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*(来源pypi)
python-magic文档
Github:python-magic
免责声明:内容编辑自网络,仅供参考,不保证正确性,不作任何决策依据!!以上数据皆截止于博文的写稿日期。