当前位置: 动力学知识库 > 问答 > 编程问答 >

Python stream views

问题描述:

Python has memoryview for viewing buffers.

Is there something analogous for io streams, or some library which implements this?

An example of what I'm thinking would be (doesn't work of course):

>>> import io

>>> sr = io.BytesIO(b'12345')

>>> print(sr[2:3]).read()

... b'3'

(this is just an example, the underlying stream doesn't have to be a buffer at all)

The reason I want views over plain bytes is that the contents underlying the stream may be very large.

网友答案:

You may consider mmap module. As far as I understand your needs it may provide required functionality.

分享给朋友:
您可能感兴趣的文章:
随机阅读: