映射协议¶
参见 PyObject_GetItem()、PyObject_SetItem() 与 PyObject_DelItem()。
-
int
PyMapping_Check(PyObject *o)¶ Return
1if the object provides mapping protocol or supports slicing, and0otherwise. Note that it returns1for Python classes with a__getitem__()method since in general case it is impossible to determine what the type of keys it supports. This function always succeeds.
-
Py_ssize_t
PyMapping_Size(PyObject *o)¶ -
Py_ssize_t
PyMapping_Length(PyObject *o)¶ 成功时返回对象 o 中键的数量,失败时返回
-1。 这相当于 Python 表达式len(o)。
-
PyObject*
PyMapping_GetItemString(PyObject *o, const char *key)¶ - Return value: New reference.
Return element of o corresponding to the string key or NULL on failure. This is the equivalent of the Python expression
o[key]. See alsoPyObject_GetItem().
-
int
PyMapping_SetItemString(PyObject *o, const char *key, PyObject *v)¶ 在对象 o 中将字符串 key 映射到值 v。 失败时返回
-1。 这相当于 Python 语句o[key] = v。 另请参见PyObject_SetItem()。
-
int
PyMapping_DelItem(PyObject *o, PyObject *key)¶ 从对象 o 中移除对象 key 的映射。 失败时返回
-1。 这相当于 Python 语句del o[key]。 这是PyObject_DelItem()的一个别名。
-
int
PyMapping_DelItemString(PyObject *o, const char *key)¶ 从对象 o 中移除字符串 key 的映射。 失败时返回
-1。 这相当于 Python 语句del o[key]。
-
int
PyMapping_HasKey(PyObject *o, PyObject *key)¶ 如果映射对象具有键 key 则返回
1,否则返回0。 这相当于 Python 表达式key in o。 此函数总是会成功执行。请注意在调用
__getitem__()方法期间发生的异常将会被屏蔽。 要获取错误报告请改用PyObject_GetItem()。
-
int
PyMapping_HasKeyString(PyObject *o, const char *key)¶ 如果映射对象具有键 key 则返回
1,否则返回0。 这相当于 Python 表达式key in o。 此函数总是会成功执行。请注意在调用
__getitem__()方法期间发生的异常将会被屏蔽。 要获取错误报告请改用PyMapping_GetItemString()。
-
PyObject*
PyMapping_Keys(PyObject *o)¶ - Return value: New reference.
On success, return a list or tuple of the keys in object o. On failure, return NULL.
