- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我有以下问题。代码如下:
import binascii, struct
def crc32up(data):
# little endian!!
bin = struct.pack ('<I', binascii.crc32 (data))
return string.upper (binascii.hexlify (bin))
# Generate crc of time code.
#
timecrc_code = crc32up(time_code)
警告是:
DeprecationWarning: struct integer overflow masking is deprecated
timecrc_code = crc32up(time_code)
是什么导致了这个错误?
最佳答案
您试图打包到您为它们分配的 4 个字节中的值太大:
>>> import struct
>>> n = 2 ** 32
>>> n
4294967296L
>>> struct.pack('<I', n - 1)
'\xff\xff\xff\xff'
>>> struct.pack('<I', n)
__main__:1: DeprecationWarning: struct integer overflow masking is deprecated
'\x00\x00\x00\x00'
较新的 python 版本 (>= 2.6) 还会警告您接受的值:
>>> import struct
>>> struct.pack('<I', -1)
__main__:1: DeprecationWarning: struct integer overflow masking is deprecated
__main__:1: DeprecationWarning: 'I' format requires 0 <= number <= 4294967295
'\xff\xff\xff\xff'
python 告诉您的是,它必须屏蔽值以适合 4 个字节;您可以使用 value & 0xFFFFFFFF
自行执行此操作。
警告仅在 python 程序执行期间发出一次。
请注意,从 2.6 开始,binascii.crc32
值始终是一个有符号 4 字节值,您应该始终使用掩码来打包这些值。这在 2.6 之前并不总是一致的,并且取决于平台。参见 the documentation了解详情。
关于python - 弃用警告 : struct integer overflow masking is deprecated,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12339785/
我正在尝试执行 JavaPairRDD 和 JavaPairRDD 的 leftOuterJoin> 并且函数签名返回类型是 JavaPairRDD>>> 这里可选的是 com.google.comm
我正在尝试按元素的频率对元素进行排序 import java.io.BufferedReader; import java.io.IOException; import java.io.InputSt
这个问题已经有答案了: Is List a subclass of List? Why are Java generics not implicitly polymorphic? (19 个回答) 已
编辑:问题已解决:请参阅 Karim SNOUSSI 的答案和我在下面的评论。 这是我在堆栈溢出时遇到的第一个问题,所以我可能不会一开始就把所有事情都做对。对此感到抱歉。此外,我对 Java 和一般
#include #include using namespace std; class Integer { public: int i; Integer (int ll
我不明白: ArrayList list = new ArrayList(); Collection list1 = new ArrayList(); 类 ArrayList扩展实现接口(interf
我编写了:。它成功了。我不知道为什么?
我编写了:。它成功了。我不知道为什么
我编写了:。它成功了。我不知道为什么?
Collectors.counting()返回 long此方法中每个键的值: private static Map countDuplicates(HashSet cards) { retur
我正在尝试通过搜索旧元素并将其替换为新元素来更新节点的元素。但是有一个我不明白的错误。是什么导致我的代码出现该错误,我该如何解决?错误; The method update(Integer, Inte
我有一个称为 client 的表,其中有一列称为created_time ,所以实际上我想绘制一个 map ,以便我可以知道在哪一年和哪一个月添加了多少客户?现在的要求是假设在 2018 年 11 月
这个问题已经有答案了: Is Java "pass-by-reference" or "pass-by-value"? (91 个回答) 已关闭 8 年前。 我对 ArrayList Collecti
我意识到下面的代码是正确的 Integer.MIN_VALUE == -Integer.MIN_VALUE == Math.abs(Integer.MIN_VALUE) 这是因为当我们取反-21474
我有以下类 AccountWebappGridRow,它扩展了 AccountGridRow: public class AccountWebappGridRow extends AccountGri
我正在学习 Haskell 并看到了函数组合。 尝试复合 map和 foldl mapd = (map.foldl) 比 test = (mapd (\x y -> x + y ) [1,2,3,4]
我有两个相同大小的数组和两个方法。 public class Client { private static int[] ints; private static final int
我喜欢 Java 8 中的 Streams 概念。现在我想借助 Java Streams 将 Java 中的 Map 转换为排序列表。我只想显示列表而不将其存储在任何地方。我希望在结果列表中有这个输出
我有一个数据库表,其中包含电视节目类型列表和关联的 ARGB 颜色值,用于在显示电视指南时突出显示 Android ListView 中的电视节目。流派表看起来像这样... id genre
我有一个 Integer 类,它应该模拟一个整数 mod n。因此,它具有如下构造函数: Integer::Integer(int x) : m(x), n(0) { } Integer::I
我是一名优秀的程序员,十分优秀!