[Python-Dev] Adding bytes.frombuffer() constructor to PEP 467

INADA Naoki songofacandy at gmail.com
Thu Jan 5 19:11:54 EST 2017


>
> bytes.frombuffer(x) is bytes(memoryview(x)) or memoryview(x).tobytes().
>

There is pitfall: memoryview should be closed.
So b = bytes.frombuffer(x) is:

with memoryview(x) as m:
    b = bytes(m)
    # or b = m.tobytes()


More information about the Python-Dev mailing list