Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
可能重复: 如何在 python 中查找文件的 mime 类型?
我想检测文件的类型,但我不想查看扩展名,因为它可能不正确。该mimetypes模块是基于文件名的。
mimetypes
有没有标准的方法来查看文件?
尝试安装python-magic模块。
>>> mime = magic.Magic(mime=True) >>> mime.from_file("testdata/abc.pdf") 'application/pdf'