매핑 프로토콜¶
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 raiseKeyError
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, return0
and set *result toNULL
; theKeyError
is silenced. If an error other thanKeyError
is raised, return-1
and set *result toNULL
.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에서 변경: 이전에는 함수가 리스트나 튜플을 반환했습니다.