python - 为什么 Python 数组模块以不同方式处理字符串和列表?

标签 python arrays type-conversion python-module

我无法理解以下语句的结果:

>>> 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/

相关文章:

python - Python中的递归函数调用

arrays - 从多维数组返回一个 n×1 矩阵

arrays - Hive 表数组列 - 使用 array_index 展开

URL 的 MySQL 数据类型

initialization - 用 Go 中的类型声明替换包装结构

python - rpy2 无法导入 'rgl' R 包

python - 如何让屏幕忽略某些图像的背景颜色?

javascript - 无法将结果推送到 JavaScript 字典

c++ - 在 C++ 中将秒数转换为 UNIX 时间戳

python - 无法从 setUpClass 调用本地方法