跳转到主要内容

在IPython中改进bytes的repr

项目描述

mimebytes

  • 在ipython中改进bytes的repr
  • 使用_repr_png__repr_jpeg_在Jupyter中获得丰富的输出
In [1]: from mimebytes import mime

In [2]: with open('image.png', 'rb') as f:
   ...:     content = f.read()

In [3]: mime(content, 'image/png')
Out[3]: PNGBytes<376151> (image/png)

preview

如果已安装python-magic,则无需指定MIME类型,因为它将自动检测。

In [1]: from mimebytes import mime

In [2]: with open('image.png', 'rb') as f:
   ...:     content = f.read()

In [3]: mime(content)
Out[3]: PNGBytes<376151> (image/png)

为什么?

您是否曾经尝试在ipython中输出一个bytes对象,看到如下混乱的输出?如果是这样,那么这个项目就是为您准备的。

In [1]: with open('image.png', 'rb') as f:
   ...:     content = f.read()
   ...:

In [2]: content
Out[2]: b'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x02\x00\x00\x00\x01\xd1\x08\x06\x00\x00\x00\x1c\xf2\x01\xed\x00\x00 \x00IDATx\x9c\xec\xbdy\x9cfWU\xef\xfd\xddk\xefs\x9e\xb1\xc6\xee\xeaNO\xe9$\x9d9\x84$\x1d\x08\x19\x84@\x80\x10@\x01\x15d\x14D\x05\x15\x05\x05\xe1\xe2\xf0^\xbdr\xf5\xeau\x06\x04E#*<... continues on forever>

项目详情


下载文件

下载适合您平台的文件。如果您不确定选择哪个,请了解更多关于安装软件包的信息。

源代码分发

mimebytes-0.2.0.tar.gz (3.8 kB 查看哈希值)

上传时间: 源代码

构建分发

mimebytes-0.2.0-py3-none-any.whl (4.6 kB 查看哈希值)

上传时间: Python 3

由以下支持