是否有 unix“文件"的 python 等价物?公用事业? [英] Is there a python-equivalent of the unix "file" utility?

查看:32
本文介绍了是否有 unix“文件"的 python 等价物?公用事业?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 python 脚本中有不同的行为,这取决于文件的类型.我不能使用文件扩展名,因为它可能不存在或误导.我可以调用 file 实用程序并解析输出,但为了可移植性,我宁愿使用 python 内置程序.

I want to have different behavior in a python script, depending on the type of file. I cannot use the filename extension as it may not be present or misleading. I could call the file utility and parse the output, but I would rather use a python builtin for portability.

那么python中是否有使用启发式方法从文件内容推断文件类型的东西?

So is there anything in python that uses heuristics to deduce the type of the file from its contents?

推荐答案

  • python-magic
  • pymagic
  • 可能还有其他人.magic"是要搜索的魔法关键字.;-)

    Probably others as well. "magic" is the magic keyword to search for. ;-)

    这篇关于是否有 unix“文件"的 python 等价物?公用事业?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆