generic_file.py 文件源码

python
阅读 16 收藏 0 点赞 0 评论 0

项目:file-metadata 作者: pywikibot-catfiles 项目源码 文件源码
def mime(self):
        if hasattr(magic, "from_file"):
            # Use https://pypi.python.org/pypi/python-magic
            return magic.from_file(self.fetch('filename'), mime=True)
        elif hasattr(magic, "open"):
            # Use the python-magic library in distro repos from the `file`
            # command - http://www.darwinsys.com/file/
            magic_instance = magic.open(magic.MAGIC_MIME)
            magic_instance.load()
            return magic_instance.file(self.fetch('filename'))

        raise ImportError(
            'The `magic` module that was found is not the expected pypi '
            'package python-magic (https://pypi.python.org/pypi/python-magic) '
            'nor file\'s (http://www.darwinsys.com/file/) package.')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号