이터레이터 프로토콜

특히 이터레이터를 사용하기 위한 두 함수가 있습니다.

int PyIter_Check(PyObject *o)
Part of the 안정 ABI 버전 3.8 이후로.

Return non-zero if the object o can be safely passed to PyIter_NextItem() and 0 otherwise. This function always succeeds.

int PyAIter_Check(PyObject *o)
Part of the 안정 ABI 버전 3.10 이후로.

객체 oAsyncIterator 프로토콜을 지원하면 0이 아닌 값을, 그렇지 않으면 0을 돌려줍니다. 이 함수는 항상 성공합니다.

Added in version 3.10.

int PyIter_NextItem(PyObject *iter, PyObject **item)
Part of the 안정 ABI 버전 3.14 이후로.

Return 1 and set item to a strong reference of the next value of the iterator iter on success. Return 0 and set item to NULL if there are no remaining values. Return -1, set item to NULL and set an exception on error.

Added in version 3.14.

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

This is an older version of PyIter_NextItem(), which is retained for backwards compatibility. Prefer PyIter_NextItem().

이터레이터 o에서 다음 값을 반환합니다. 객체는 PyIter_Check()에 따르는 이터레이터 여야 합니다 (이것을 확인하는 것은 호출자 책임입니다). 남은 값이 없으면, 예외가 설정되지 않은 상태로 NULL을 반환합니다. 항목을 꺼내는 동안 에러가 발생하면, NULL을 반환하고 예외를 전달합니다.

type PySendResult

The enum value used to represent different results of PyIter_Send().

Added in version 3.10.

PySendResult PyIter_Send(PyObject *iter, PyObject *arg, PyObject **presult)
Part of the 안정 ABI 버전 3.10 이후로.

Sends the arg value into the iterator iter. Returns:

  • PYGEN_RETURN if iterator returns. Return value is returned via presult.

  • PYGEN_NEXT if iterator yields. Yielded value is returned via presult.

  • PYGEN_ERROR if iterator has raised and exception. presult is set to NULL.

Added in version 3.10.