Serhiy Storchaka added the comment:

Following example copies the entire buffer object while copying only smart part 
is needed:

    m = memoryview(b'x'*10**6)
    b'%.100b' % m

I don't know whether this is important use case that is worth an optimization. 
The workaround is using slicing rather than truncating in format:

    b'%b' % m[:100]

Or in the case of general buffer object:

    b'%b' % memoryview(m).cast('B')[:100]

But in that case it is not hard to add an explicit conversion to bytes.

    b'%b' % bytes(memoryview(m).cast('B')[:100])

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue28856>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to