我无法理解以下语句的结果:
>>> from array import array
>>> array('L',[0xff,0xff,0xff,0xff])
array('L', [255L, 255L, 255L, 255L])
>>> from array import array
>>> array('L','\xff\xff\xff\xff')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: string length not a multiple of item size
最佳答案
您正在 64 位 Python 版本上运行它,array
将类型代码 'L'
视为 64 位无符号整数。
>>> array('L','\xff\xff\xff\xff\xff\xff\xff\xff')
array('L', [18446744073709551615L])
文档不是很清楚。它只是说 'L'
至少有四个字节。
关于python - 为什么 Python 数组模块以不同方式处理字符串和列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2752913/