python读取文件类型_Python使用filetype精确判断文件类型 (文件类型获取)
filetype.py
Small and dependency free Python package to infer file type and MIME type checking the magic numbers signature of a file or buffer.
This is a Python port from filetype Go package. Works in Python +3 .
一个小巧自由开放Python开发包,主要用来获得文件类型。包要求Python 3.+
功能特色
•简单友好的API
•支持宽范围文件类型
•提供文件扩展名和MIME类型判断
•文件的MIME类型扩展新增
•通过文件(图像、视频、音频…)简单分析
•可插拔:添加新的自定义类型的匹配
•快,即使处理大文件
•只需要前261个字节表示的最大文件头,这样你就可以通过一个单字节
•依赖自由(只是Python代码,没有C的扩展,没有libmagic绑定)
•跨平台文件识别
安装
pip install filetype
API
实例
简单的文件类型识别
importfiletypedefmain():
kind= filetype.guess('tests/fixtures/sample.jpg')if kind isNone:print('Cannot guess file type!')return
print('File extension: %s' %kind.extension)print('File MIME type: %s' %kind.mime)if __name__ == '__main__':
main()
支持类型
图片
• jpg – image/jpeg
• png – image/png
• gif – image/gif
• webp – image/webp
• cr2 – image/x-canon-cr2
• tif – image/tiff
• bmp – image/bmp
• jxr – image/vnd.ms-photo
• psd – image/vnd.adobe.photoshop
• ico – image/x-icon
视频
• mp4 – video/mp4
• m4v – video/x-m4v
• mkv – video/x-matroska
• webm – video/webm
• mov – video/quicktime
• avi – video/x-msvideo
• wmv – video/x-ms-wmv
• mpg – video/mpeg
• flv – video/x-flv
音频
• mid – audio/midi
• mp3 – audio/mpeg
• m4a – audio/m4a
• ogg – audio/ogg
• flac – audio/x-flac
• wav – audio/x-wav
• amr – audio/amr
资料库
• epub – application/epub+zip
• zip – application/zip
• tar – application/x-tar
• rar – application/x-rar-compressed
• gz – application/gzip
• bz2 – application/x-bzip2
• 7z – application/x-7z-compressed
• xz – application/x-xz
• pdf – application/pdf
• exe – application/x-msdownload
• swf – application/x-shockwave-flash
• rtf – application/rtf
• eot – application/octet-stream
• ps – application/postscript
• sqlite – application/x-sqlite3
• nes – application/x-nintendo-nes-rom
• crx – application/x-google-chrome-extension
• cab – application/vnd.ms-cab-compressed
• deb – application/x-deb
• ar – application/x-unix-archive
• Z – application/x-compress
• lz – application/x-lzip
字体
• woff – application/font-woff
• woff2 – application/font-woff
• ttf – application/font-sfnt
• otf – application/font-sfnt
python读取文件类型_Python使用filetype精确判断文件类型 (文件类型获取)相关推荐
- python获取文件后缀_Python使用filetype精确判断文件类型 (文件类型获取)
filetype.py Small and dependency free Python package to infer file type and MIME type checking the m ...
- python如何区分文件类型_Python使用filetype精确判断文件类型
filetype.py Small and dependency free Python package to infer file type and MIME type checking the m ...
- python判断图片类型_Python使用filetype精确判断文件类型
filetype.py Small and dependency free Python package to infer file type and MIME type checking the m ...
- python脚本文件格式_Python使用filetype精确判断文件类型
filetype.py Small and dependency free Python package to infer file type and MIME type checking the m ...
- python读取表格数据_Python读取Excel数据并根据列名取值
一直想将自己接触到的东西梳理一遍,可就是迈不出第一步,希望从这篇总结开始不要再做行动的矮人了. 最近测试过程中需要用到python读取excel用例数据,于是去了解和学习了下xlrd库,这里只记录使用 ...
- python如何区分文件类型_Python库 使用filetype精确判断文件类型
一个小巧自由开放Python开发包,主要用来获得文件类型. filetype支持版本: python2/python3 filetype安装: pip install filetype filetyp ...
- Python库 使用filetype精确判断文件类型
filetype判断文件类型 作用 一个小巧自由开放Python开发包,主要用来获得文件类型. 支持版本: python2/python3 安装: pip install filetype 功能特色 ...
- python读取坐标文本文件_Python 实现文件读写、坐标寻址、查找替换功能
读文件 打开文件(文件需要存在) #打开文件 f = open("data.txt","r") #设置文件对象 print(f)#文件句柄 f.close() ...
- python读取大文件目录_Python读取系统文件夹内所有文件并统计数量的方法
大家先看一下Python os模块中的部分函数 python 路径相关的函数 os.listdir(dirname):列出dirname下的目录和文件 os.getcwd():获得当前工作目录 os. ...
最新文章
- matlab自适应逆控制,基于matlab仿真模块的自适应有源噪声逆控制研究
- 百度新key申请步骤
- ssm整合之六 时间日期装换
- Fis3的前端工程化之路[三大特性篇之资源定位]
- 目标检测第8步:如何在Windows10系统下,训练YOLOv5 5.0自定义数据集?(本地)
- oracle 随机排列,oracle的随机排序
- zabbix监控特殊端口(8080,80,8009等)
- 【英语学习】【English L06】U01 Breakfast L2 A large breakfast
- textaligncenter仍然不居中_5个word你不知道的功能
- count函数_计数函数Count、Counta、Countblank、Countif、Countifs技巧解读
- iframe给php传值,向iframe传递参数
- Amber Group创始人兼CEO Michael Wu:CBDC将成为更广义、重要的加密资产
- dojo uploader使用,ps.返回值
- 剖析Elasticsearch集群系列之二:分布式的三个C、translog和Lucene段
- PHP微信多级三级分佣系统,微信多级三级分销系统 多级三级分佣模式 支付宝微信双支付...
- linux下redis常用命令
- [Vue]鼠标悬停变色
- 天下3各服务器最新互转查询,转服必看 大荒最新服务器火爆度排行榜
- 没有学历怎么找运维工作?
- 英雄!「安可心」请你跳支舞
热门文章
- 同时使用有线网上内网、无线网上外网
- Vision and Art ,The Biology of Seeing 读书笔记
- 监控远程桌面连接并通过python发送提醒邮件
- 计算机开机桌面黑屏,电脑开机后黑屏 - 笔记本开机后黑屏的解决办法 - 安全专题...
- 当ChatGP遇上数据库,看完我不淡定了......
- offsetTop问题
- 转:从桌面到云端 —— PC-cillin的22年杀毒史
- 关于PublicCMS二次开发的源码学习 表单
- 以酶促反应为例的统计回归问题及代码实现
- Adobe Acrobat 8 Professional(PDFMaker文件遗失的解决方法)