生成器对象¶
生成器对象是Python用来实现生成器迭代器的对象。它们通常通过迭代产生值的函数来创建,而不是显式调用 PyGen_New() 或 PyGen_NewWithQualName()。
-
type PyGenObject¶
用于生成器对象的C结构体。
-
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。
-
PyCodeObject *PyGen_GetCode(PyGenObject *gen)¶
Return a new strong reference to the code object wrapped by gen. This function always succeeds.
Asynchronous Generator Objects¶
参见
-
PyTypeObject PyAsyncGen_Type¶
The type object corresponding to asynchronous generator objects. This is available as
types.AsyncGeneratorTypein the Python layer.Added in version 3.6.
-
PyObject *PyAsyncGen_New(PyFrameObject *frame, PyObject *name, PyObject *qualname)¶
Create a new asynchronous generator wrapping frame, with
__name__and__qualname__set to name and qualname. frame is stolen by this function and must not beNULL.On success, this function returns a strong reference to the new asynchronous generator. On failure, this function returns
NULLwith an exception set.Added in version 3.6.