物件協定

PyObject *Py_GetConstant(unsigned int constant_id)
穩定 ABI 的一部分 自 3.13 版本開始.

Get a strong reference to a constant.

如果 constant_id 無效,則設定一個例外並回傳 NULL

constant_id 必須是這些常數識別字之一:

常數識別字

數值

回傳物件

Py_CONSTANT_NONE

0

None

Py_CONSTANT_FALSE

1

False

Py_CONSTANT_TRUE

2

True

Py_CONSTANT_ELLIPSIS

3

Ellipsis

Py_CONSTANT_NOT_IMPLEMENTED

4

NotImplemented

Py_CONSTANT_ZERO

5

0

Py_CONSTANT_ONE

6

1

Py_CONSTANT_EMPTY_STR

7

''

Py_CONSTANT_EMPTY_BYTES

8

b''

Py_CONSTANT_EMPTY_TUPLE

9

()

Numeric values are only given for projects which cannot use the constant identifiers.

在 3.13 版被加入.

在 CPython 中,所有這些常數都是不滅的。

PyObject *Py_GetConstantBorrowed(unsigned int constant_id)
穩定 ABI 的一部分 自 3.13 版本開始.

Similar to Py_GetConstant(), but return a borrowed reference.

This function is primarily intended for backwards compatibility: using Py_GetConstant() is recommended for new code.

The reference is borrowed from the interpreter, and is valid until the interpreter finalization.

在 3.13 版被加入.

PyObject *Py_NotImplemented

The NotImplemented singleton, used to signal that an operation is not implemented for the given type combination.

Py_RETURN_NOTIMPLEMENTED

Properly handle returning Py_NotImplemented from within a C function (that is, create a new strong reference to NotImplemented and return it).

Py_PRINT_RAW

Flag to be used with multiple functions that print the object (like PyObject_Print() and PyFile_WriteObject()). If passed, these functions use the str() of the object instead of the repr().

int PyObject_Print(PyObject *o, FILE *fp, int flags)

Print an object o, on file fp. Returns -1 on error. The flags argument is used to enable certain printing options. The only option currently supported is Py_PRINT_RAW; if given, the str() of the object is written instead of the repr().

int