【发布时间】:2013-11-08 22:08:24
【问题描述】:
我一直在尝试探索 python 如何在我的系统上存储 longs 符号。
不确定是不是这样,我已经尝试过buffer(long(-10)),希望它能拉近我的距离。
但我有TypeError: buffer object expected。
来自help(buffer):
class buffer(object)
| buffer(object [, offset[, size]])
|
| Create a new buffer object which references the given object.
| The buffer will reference a slice of the target object from the
| start of the object (or at the specified offset). The slice will
| extend to the end of the target object (or with the specified size).
我认为一切都是 python 中的对象,我解释了这个文档字符串,以便我可以将任何对象提供给缓冲区的 init。好像不是这样的。
你能帮我理解发生了什么吗?
【问题讨论】:
-
“我一直在尝试探索 python 如何在我的系统上存储 longs 的符号。”然后只需下载源代码并阅读
Include/longintrepr.h。引用:Negative numbers are represented with ob_size < 0; zero is represented by ob_size == 0.要了解ob_size是什么,您应该阅读 Python C/API 的PyObject_VAR_HEAD宏。