生成器对象¶
生成器对象是Python用来实现生成器迭代器的对象。它们通常通过迭代产生值的函数来创建,而不是显式调用 PyGen_New()
或 PyGen_NewWithQualName()
。
-
type
PyGenObject
¶ 用于生成器对象的C结构体。
-
type
PySendResult
¶ The enum value used to represent different results of
PyGen_Send()
.
-
PyTypeObject
PyGen_Type
¶ 与生成器对象对应的类型对象。
-
int
PyGen_CheckExact
(PyObject *ob)¶ 如果 ob 的类型为
PyGen_Type
则返回真值;ob 必须不为NULL
。
-
PyObject *
PyGen_New
(PyFrameObject *frame)¶ 基于 frame 对象创建并返回一个新的生成器对象。 此函数会取走一个对 frame 的引用。 参数必须不为
NULL
。
-
PyObject *
PyGen_NewWithQualName
(PyFrameObject *frame, PyObject *name, PyObject *qualname)¶ 基于 frame 对象创建并返回一个新的生成器对象,其中
__name__
和__qualname__
设为 name 和 qualname。 此函数会取走一个对 frame 的引用。 frame 参数必须不为NULL
。
-
PySendResult
PyGen_Send
(PyGenObject *gen, PyObject *arg, PyObject **presult)¶ Sends the arg value into the generator gen. Coroutine objects are also allowed to be as the gen argument but they need to be explicitly casted to PyGenObject*. Returns:
PYGEN_RETURN
if generator returns. Return value is returned via presult.PYGEN_NEXT
if generator yields. Yielded value is returned via presult.PYGEN_ERROR
if generator has raised and exception. presult is set toNULL
.