问题描述:

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.

相关阅读:
Top