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

2016年10月12日 02:45:16 -0700

On Wed, Oct 12, 2016 at 2:32 PM, Serhiy Storchaka <[email protected]> wrote:
> On 12.10.16 07:08, INADA Naoki wrote:
>>
>> Sample code:
>>
>> def read_line(buf: bytearray) -> bytes:
>> try:
>> n = buf.index(b'\r\n')
>> except ValueError:
>> return b''
>>
>> line = bytes(buf)[:n] # bytearray -> bytes -> bytes
>
>
> Wouldn't be more correct to write this as bytes(buf[:n])?
Yes, you're right!
I shouldn't copy whole data only for cast from bytearray to byte.
>
>> Adding one more constructor to bytes:
>>
>> # when length=-1 (default), use until end of *byteslike*.
>> bytes.frombuffer(byteslike, length=-1, offset=0)
>
>
> This interface looks unusual. Would not be better to support the interface
> of buffer in Python 2: buffer(object [, offset[, size]])?
>
It looks better.
(Actually speaking, I love deprecated old buffer for simplicity.
memoryview supports non bytes-like complex data types.)
Thanks,
-- 
INADA Naoki <[email protected]>
_______________________________________________
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