ctypes.c_long(0L) 对于 Python 3x

ctypes.c_long(0L) for Python 3x

我正在运行从 Python 2x 到 Python 3x 的定位,我正在使用 ctypes。在 Python 2x 上,下面的代码 运行 完美:

ctypes.c_long(0L)

但是,0L 是 Python 3x 的无效语法。我有办法解决这个问题吗?

你不需要末尾的 L。就做 ctypes.c_long(0)。据我了解,这是因为 Python 3x maps c_long to Python type int, whereas Python 2x allowed int or long. This, in turn, comes from the fact that there is no more 内置 long 类型。