1. 程式人生 > >python學習之io模塊

python學習之io模塊

pan font nbsp get mic color blog 內存 import

class io.BytesIO([initial_bytes])

他是一個_io.BytesIO對象。

用這個類的實例可以操作內存緩沖區中的字節流。

>>> s = hello
>>> b = s.encode()
>>> b
bhello
>>> import io
>>> a = io.BytesIO(b)
>>> a
<_io.BytesIO object at 0x00000064DF5DA2B0>
>>> c = a.getbuffer()
>>> c
<memory at 0x00000064DF5F0648>

>>> n = ‘12‘
>>> b1 = n.encode()
>>> c[1:3] = b1
>>> a.getvalue()
b‘h12lo‘

使用該類的實例可以創建緩沖區並在緩沖區中操作字節流。

python學習之io模塊