映射協(xié)議?
參見 PyObject_GetItem()
、PyObject_SetItem()
與 PyObject_DelItem()
。
-
int PyMapping_Check(PyObject *o)?
- Part of the Stable ABI.
Return
1
if the object provides the mapping protocol or supports slicing, and0
otherwise. Note that it returns1
for Python classes with a__getitem__()
method, since in general it is impossible to determine what type of keys the class supports. This function always succeeds.
-
Py_ssize_t PyMapping_Size(PyObject *o)?
-
Py_ssize_t PyMapping_Length(PyObject *o)?
- Part of the Stable ABI.
成功時返回對象 o 中鍵的數(shù)量,失敗時返回
-1
。 這相當(dāng)于 Python 表達式len(o)
。
-
PyObject *PyMapping_GetItemString(PyObject *o, const char *key)?
- Return value: New reference. Part of the Stable ABI.
返回 o 中對應(yīng)于字符串 key 的元素,或者失敗時返回
NULL
。 這相當(dāng)于 Python 表達式o[key]
。 另請參見 alsoPyObject_GetItem()
。
-
int PyMapping_SetItemString(PyObject *o, const char *key, PyObject *v)?
- Part of the Stable ABI.
在對象 o 中將字符串 key 映射到值 v。 失敗時返回
-1
。 這相當(dāng)于 Python 語句o[key] = v
。 另請參見PyObject_SetItem()
。 此函數(shù) 不會 增加對 v 的引用。
-
int PyMapping_DelItem(PyObject *o, PyObject *key)?
從對象 o 中移除對象 key 的映射。 失敗時返回
-1
。 這相當(dāng)于 Python 語句del o[key]
。 這是PyObject_DelItem()
的一個別名。
-
int PyMapping_DelItemString(PyObject *o, const char *key)?
從對象 o 中移除字符串 key 的映射。 失敗時返回
-1
。 這相當(dāng)于 Python 語句del o[key]
。
-
int PyMapping_HasKey(PyObject *o, PyObject *key)?
- Part of the Stable ABI.
如果映射對象具有鍵 key 則返回
1
,否則返回0
。 這相當(dāng)于 Python 表達式key in o
。 此函數(shù)總是會成功執(zhí)行。請注意在調(diào)用
__getitem__()
方法期間發(fā)生的異常將會被屏蔽。 要獲取錯誤報告請改用PyObject_GetItem()
。
-
int PyMapping_HasKeyString(PyObject *o, const char *key)?
- Part of the Stable ABI.
如果映射對象具有鍵 key 則返回
1
,否則返回0
。 這相當(dāng)于 Python 表達式key in o
。 此函數(shù)總是會成功執(zhí)行。請注意在調(diào)用
__getitem__()
方法期間發(fā)生的異常將會被屏蔽。 要獲取錯誤報告請改用PyMapping_GetItemString()
。
-
PyObject *PyMapping_Keys(PyObject *o)?
- Return value: New reference. Part of the Stable ABI.
成功時,返回對象 o 中的鍵的列表。 失敗時,返回
NULL
。在 3.7 版更改: 在之前版本中,此函數(shù)返回一個列表或元組。
-
PyObject *PyMapping_Values(PyObject *o)?
- Return value: New reference. Part of the Stable ABI.
成功時,返回對象 o 中的值的列表。 失敗時,返回
NULL
。在 3.7 版更改: 在之前版本中,此函數(shù)返回一個列表或元組。
-
PyObject *PyMapping_Items(PyObject *o)?
- Return value: New reference. Part of the Stable ABI.
成功時,返回對象 o 中條目的列表,其中每個條目是一個包含鍵值對的元組。 失敗時,返回
NULL
。在 3.7 版更改: 在之前版本中,此函數(shù)返回一個列表或元組。