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

2017年1月06日 04:07:01 -0800

On Thu, 5 Jan 2017 20:28:26 -0500
Yury Selivanov <[email protected]> wrote:
> On 2017年01月05日 7:11 PM, INADA Naoki wrote:
> >> 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() 
> 
> Thinking more about this, and after looking at my own code in asyncpg 
> and uvloop, I'm now in favor of adding bytes.frombuffer() with the 
> proposed signature: ``bytes.frombuffer(byteslike, length=-1, offset=0)``
+1
Note this matches numpy.frombuffer():
"""
frombuffer(buffer, dtype=float, count=-1, offset=0)
Interpret a buffer as a 1-dimensional array.
"""
Regards
Antoine.
_______________________________________________
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to