對映協定

另請參閱PyObject_GetItem()PyObject_SetItem()PyObject_DelItem()

intPyMapping_Check(PyObject*o)
穩定 ABI 的一部分.

如果物件有提供對映協定或支援切片 (slicing) 則回傳1,否則回傳0。請注意,對於具有__getitem__() 方法的 Python 類別,它會回傳1,因為通常無法確定該類別支援什麼類型的鍵。這個函式總會是成功的。

Py_ssize_tPyMapping_Size(PyObject*o)
Py_ssize_tPyMapping_Length(PyObject*o)
穩定 ABI 的一部分.

成功時回傳物件o 中的鍵數,失敗時回傳-1。這相當於 Python 運算式len(o)

PyObject*PyMapping_GetItemString(PyObject*o,constchar*key)
回傳值:新的參照。穩定 ABI 的一部分.

這與PyObject_GetItem() 相同,但key 被指定為constchar* UTF-8 編碼位元組字串,而不是PyObject*

intPyMapping_GetOptionalItem(PyObject*obj,PyObject*key,PyObject**result)
穩定 ABI 的一部分 自 3.13 版本開始.

Variant ofPyObject_GetItem() which doesn't raiseKeyError if the key is not found.

If the key is found, return1 and set*result to a newstrong reference to the corresponding value.If the key is not found, return0 and set*result toNULL;theKeyError is silenced.If an error other thanKeyError is raised, return-1 andset*result toNULL.

在 3.13 版被加入.

intPyMapping_GetOptionalItemString(PyObject*obj,constchar*key,PyObject**result)
穩定 ABI 的一部分 自 3.13 版本開始.

This is the same asPyMapping_GetOptionalItem(), butkey isspecified as aconstchar* UTF-8 encoded bytes string,rather than aPyObject*.

在 3.13 版被加入.

intPyMapping_SetItemString(PyObject*o,constchar*key,PyObject*v)
穩定 ABI 的一部分.

這與PyObject_SetItem() 相同,但key 被指定為constchar* UTF-8 編碼位元組字串,而不是PyObject*

intPyMapping_DelItem(PyObject*o,PyObject*key)

這是PyObject_DelItem() 的別名。

intPyMapping_DelItemString(PyObject*o,constchar*key)

這與PyObject_DelItem() 相同,但key 被指定為constchar* UTF-8 編碼位元組字串,而不是PyObject*

intPyMapping_HasKeyWithError(PyObject*o,PyObject*key)
穩定 ABI 的一部分 自 3.13 版本開始.

Return1 if the mapping object has the keykey and0 otherwise.This is equivalent to the Python expressionkeyino.On failure, return-1.

在 3.13 版被加入.

intPyMapping_HasKeyStringWithError(PyObject*o,constchar*key)
穩定 ABI 的一部分 自 3.13 版本開始.

This is the same asPyMapping_HasKeyWithError(), butkey isspecified as aconstchar* UTF-8 encoded bytes string,rather than aPyObject*.

在 3.13 版被加入.

intPyMapping_HasKey(PyObject*o,PyObject*key)
穩定 ABI 的一部分.

如果對映物件具有鍵key 則回傳1,否則回傳0。這相當於 Python 運算式keyino。這個函式總會是成功的。

備註

Exceptions which occur when this calls__getitem__()method are silently ignored.For proper error handling, usePyMapping_HasKeyWithError(),PyMapping_GetOptionalItem() orPyObject_GetItem() instead.

intPyMapping_HasKeyString(PyObject*o,constchar*key)
穩定 ABI 的一部分.

這與PyMapping_HasKey() 相同,但key 被指定為constchar* UTF-8 編碼位元組字串,而不是PyObject*

備註

Exceptions that occur when this calls__getitem__()method or while creating the temporarystrobject are silently ignored.For proper error handling, usePyMapping_HasKeyStringWithError(),PyMapping_GetOptionalItemString() orPyMapping_GetItemString() instead.

PyObject*PyMapping_Keys(PyObject*o)
回傳值:新的參照。穩定 ABI 的一部分.

成功時回傳一個物件o 內之鍵的串列,失敗時回傳NULL

在 3.7 版的變更:在以前,該函式會回傳串列或元組。

PyObject*PyMapping_Values(PyObject*o)
回傳值:新的參照。穩定 ABI 的一部分.

成功時回傳物件o 中值的串列。失敗時回傳NULL

在 3.7 版的變更:在以前,該函式會回傳串列或元組。

PyObject*PyMapping_Items(PyObject*o)
回傳值:新的參照。穩定 ABI 的一部分.

成功時回傳物件o 內之項目的串列,其中每個項目都是包含鍵值對的元組。失敗時回傳NULL

在 3.7 版的變更:在以前,該函式會回傳串列或元組。