Created
December 22, 2014 16:37
-
-
Save superbobry/b90c0cc7c44beaa51ef9 to your computer and use it in GitHub Desktop.
Python 2/3 buffer protocol inconsistency
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Python 2 | |
>>> b = bytearray(8) | |
>>> v = memoryview(b) | |
>>> v[0] = 42 | |
Traceback (most recent call last): | |
File "<stdin>", line 1, in <module> | |
TypeError: 'int' does not have the buffer interface | |
>>> b | |
bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') | |
# Python 3 | |
>>> b = bytearray(8) | |
>>> v = memoryview(b) | |
>>> v[0] = 42 | |
>>> b | |
bytearray(b'*\x00\x00\x00\x00\x00\x00\x00') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment