开发者

Is there a python-equivalent of the unix "file" utility?

开发者 https://www.devze.com 2022-12-15 13:48 出处:网络
I want to h开发者_如何学Cave 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 uti

I want to h开发者_如何学Cave 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.

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


  • python-magic
  • pymagic

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

0

精彩评论

暂无评论...
验证码 换一张
取 消