[Python-ideas] Fixing the Python 3 bytes constructor

Alexander Belopolsky alexander.belopolsky at gmail.com
Fri Mar 28 16:36:40 CET 2014


On Fri, Mar 28, 2014 at 10:28 AM, Barry Warsaw <barry at python.org> wrote:

> I like bytearray.fill() for this.  The first argument would be the fill
> count,
> but it could take an optional second argument for the byte value to fill it
> with, which would of course default to zero.  E.g.
>
> >>> bytearray.fill(5)
> bytearray(b'\x00\x00\x00\x00\x00')
> >>> bytearray.fill(5, 97)
> bytearray(b'aaaaa')
>

In numpy this constructor is spelled "full":

>>> np.full(3, 42)
array([ 42.,  42.,  42.])

(Which makes more sense in the full context: np.zeros, np.ones, np.empty,
np.full.)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140328/e197e8ed/attachment.html>


More information about the Python-ideas mailing list