Message187968
I needed to write some bytes to file and got this message.
>>> hex = open('hex', 'wb')
>>> for x in range(0, 0xff, 0x11):
... hex.write(x)
...
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
TypeError: 'int' does not support the buffer interface
The cause of the error is not that 'int' doesn't support some interface (which is strange already, because the function analyzes and writes int, not the int writes itself), but because it is impossible to know how many binary bytes the int type should take when written.
In Python 2 the solution is:
...
hex.write(chr(x))
But in Python 3 this is again:
TypeError: 'str' does not support the buffer interface
In Python 3 the solution is:
...
hex.write(x.to_bytes(1, 'little')) |
|
Date |
User |
Action |
Args |
2013-04-28 07:37:56 | techtonik | set | recipients:
+ techtonik |
2013-04-28 07:37:56 | techtonik | set | messageid: <1367134676.21.0.161863892006.issue17859@psf.upfronthosting.co.za> |
2013-04-28 07:37:56 | techtonik | link | issue17859 messages |
2013-04-28 07:37:55 | techtonik | create | |
|