classification
Title: bytearray init fails when \x00 is present
Type: behavior Stage:
Components: Interpreter Core Versions: Python 3.4, Python 3.5, Python 2.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: bsder, r.david.murray
Priority: normal Keywords:

Created on 2014-02-26 18:10 by bsder, last changed 2014-02-27 00:19 by bsder. This issue is now closed.

Messages (3)
msg212281 - (view) Author: Andrew P. Lentvorski, Jr. (bsder) Date: 2014-02-26 18:10
The byte array init fails when \x00 is present

This fails:
ggRAM = bytearray(RAM_SIZE_BYTES, '\x00'*RAM_SIZE_BYTES)

However, this works:
ggRAM = bytearray(RAM_SIZE_BYTES)
ggRAM[:] = '\x00'*RAM_SIZE_BYTES
msg212287 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2014-02-26 18:51
That isn't a valid bytearray initialization call.  The two argument form is (string, encoding), not (size, string).  The error message you get is a bit funky and not particularly informative, though.  Maybe someone will want to try to improve that.
msg212333 - (view) Author: Andrew P. Lentvorski, Jr. (bsder) Date: 2014-02-27 00:19
Ayup, I are an idiot.  Sorry.

ggRAM = bytearray('\x00'*RAM_SIZE_BYTES)

Works fine.
History
Date User Action Args
2014-02-27 00:19:57bsdersetresolution: not a bug
2014-02-27 00:19:50bsdersetstatus: open -> closed

messages: + msg212333
2014-02-26 19:00:01r.david.murraysetstage: resolved ->
2014-02-26 18:51:23r.david.murraysetversions: + Python 3.4, Python 3.5
nosy: + r.david.murray

messages: + msg212287

stage: resolved
2014-02-26 18:10:15bsdercreate