28 Mar
2014
28 Mar
'14
3:36 p.m.
On Fri, Mar 28, 2014 at 10:28 AM, Barry Warsaw
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.)