-
-
Notifications
You must be signed in to change notification settings - Fork 32k
doc: clarify that struct.pack_into writes 0x00 for pad bytes #65002
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This code did something unexpected to me:
>>> a = bytearray('1234')
>>> a
bytearray(b'1234')
>>> struct.pack_into('xBxB', a, 0, 0x59, 0x5A)
>>> a
bytearray(b'\x00Y\x00Z') The unexpected part was that the 'x' pad byte formatter actually *overwrote* the bytes to 0 rather than leaving them alone. Not necessarily a bug, but the fact that the pad byte writes 0x00 rather than being untouched/ignored should be documented. |
Contrawise, I would have found it very surprising if it had not padded with null bytes, but yes, the docs could be explicit about it by saying that 'x' padding means inserting null bytes. |
I'm working on this |
The PR is stale. Can I work on it ? |
…onGH-98635) (cherry picked from commit 8cd21c2) Co-authored-by: Stanley <[email protected]>
…onGH-98635) (cherry picked from commit 8cd21c2) Co-authored-by: Stanley <[email protected]>
(cherry picked from commit 8cd21c2) Co-authored-by: Stanley <[email protected]>
(cherry picked from commit 8cd21c2) Co-authored-by: Stanley <[email protected]>
Thanks, looks like this has been completed |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: