매핑 프로토콜

PyObject_GetItem(), PyObject_SetItem()PyObject_DelItem()도 참조하십시오.

int PyMapping_Check(PyObject *o)
Part of the 안정 ABI.

객체가 매핑 프로토콜을 제공하거나 슬라이싱을 지원하면 1을 반환하고, 그렇지 않으면 0을 반환합니다. __getitem__() 메서드가 있는 파이썬 클래스의 경우 1을 반환한다는 점에 유의하십시오; 일반적으로 클래스가 지원하는 키 형을 판단할 수 없기 때문입니다. 이 함수는 항상 성공합니다.

Py_ssize_t PyMapping_Size(PyObject *o)
Py_ssize_t PyMapping_Length(PyObject *o)
Part of the 안정 ABI.

성공 시 객체 o의 키 수를 반환하고, 실패하면 -1을 반환합니다. 이는 파이썬 표현식 len(o)와 동등합니다.

PyObject *PyMapping_GetItemString(PyObject *o, const char *key)
반환값: 새 참조. Part of the 안정 ABI.

This is the same as PyObject_GetItem(), but key is specified as a const char* UTF-8 encoded bytes string, rather than a PyObject*.

int PyMapping_GetOptionalItem(PyObject *obj, PyObject *key, PyObject **result)
Part of the 안정 ABI 버전 3.13 이후로.

Variant of PyObject_GetItem() which doesn’t raise KeyError if the key is not found.

If the key is found, return 1 and set *result to a new strong reference to the corresponding value. If the key is not found, return 0 and set *result to NULL; the KeyError is silenced. If an error other than KeyError is raised, return -1 and set *result to NULL.

Added in version 3.13.

int PyMapping_GetOptionalItemString(PyObject *obj, const char *key, PyObject **result)
Part of the 안정 ABI 버전 3.13 이후로.

This is the same as PyMapping_GetOptionalItem(), but key is specified as a const char* UTF-8 encoded bytes string, rather than a PyObject*.

Added in version 3.13.

int PyMapping_SetItemString(PyObject *o, const char *key, PyObject *v)
Part of the 안정 ABI.

This is the same as PyObject_SetItem(), but key is specified as a const char* UTF-8 encoded bytes string, rather than a PyObject*.

int PyMapping_DelItem(PyObject *o, PyObject *key)

이것은 PyObject_DelItem()의 별칭입니다.

int PyMapping_DelItemString(PyObject *o, const char *key)

This is the same as PyObject_DelItem(), but key is specified as a const char* UTF-8 encoded bytes string, rather than a PyObject*.

int PyMapping_HasKeyWithError(PyObject *o, PyObject *key)
Part of the 안정 ABI 버전 3.13 이후로.

매핑 객체에 key 키가 있으면 1을 반환하고, 그렇지 않으면 0을 반환합니다. 이는 파이썬 표현식 key in o와 동등합니다. 실패하면 -1을 반환합니다.

Added in version 3.13.

int PyMapping_HasKeyStringWithError(PyObject *o, const char *key)
Part of the 안정 ABI 버전 3.13 이후로.

This is the same as PyMapping_HasKeyWithError(), but key is specified as a const char* UTF-8 encoded bytes string, rather than a PyObject*.

Added in version 3.13.

int PyMapping_HasKey(PyObject *o, PyObject *key)
Part of the 안정 ABI.

매핑 객체에 key 키가 있으면 1을 반환하고, 그렇지 않으면 0을 반환합니다. 이는 파이썬 표현식 key in o와 동등합니다. 이 함수는 항상 성공합니다.

참고

이 함수가 __getitem__() 메서드를 호출하는 동안 발생하는 예외는 조용히 억제됩니다. 적절한 에러 처리가 필요하면 대신 PyMapping_HasKeyWithError(), PyMapping_GetOptionalItem() 또는 PyObject_GetItem()을 사용하십시오.

int PyMapping_HasKeyString(PyObject *o, const char *key)
Part of the 안정 ABI.

This is the same as PyMapping_HasKey(), but key is specified as a const char* UTF-8 encoded bytes string, rather than a PyObject*.

참고

이 함수가 __getitem__() 메서드를 호출하거나 임시 str 객체를 만드는 동안 발생하는 예외는 조용히 억제됩니다. 적절한 에러 처리가 필요하면 대신 PyMapping_HasKeyStringWithError(), PyMapping_GetOptionalItemString() 또는 PyMapping_GetItemString()을 사용하십시오.

PyObject *PyMapping_Keys(PyObject *o)
반환값: 새 참조. Part of the 안정 ABI.

성공하면, 객체 o의 키 리스트를 반환합니다. 실패하면, NULL을 반환합니다.

버전 3.7에서 변경: 이전에는 함수가 리스트나 튜플을 반환했습니다.

PyObject *PyMapping_Values(PyObject *o)
반환값: 새 참조. Part of the 안정 ABI.

성공하면, 객체 o의 값 리스트를 반환합니다. 실패하면, NULL을 반환합니다.

버전 3.7에서 변경: 이전에는 함수가 리스트나 튜플을 반환했습니다.

PyObject *PyMapping_Items(PyObject *o)
반환값: 새 참조. Part of the 안정 ABI.

성공하면, 객체 o에 있는 항목 리스트를 반환합니다. 여기서 각 항목은 키-값 쌍을 포함하는 튜플입니다. 실패하면, NULL을 반환합니다.

버전 3.7에서 변경: 이전에는 함수가 리스트나 튜플을 반환했습니다.