函数对象¶
有一些特定于 Python 函数的函数。
-
PyFunctionObject¶ 用于函数的 C 结构体。
-
PyTypeObject
PyFunction_Type¶ 这是一个
PyTypeObject实例并表示 Python 函数类型。 它作为types.FunctionType向 Python 程序员公开。
-
int
PyFunction_Check(PyObject *o)¶ Return true if o is a function object (has type
PyFunction_Type). The parameter must not be NULL.
-
PyObject*
PyFunction_New(PyObject *code, PyObject *globals)¶ - Return value: New reference.
返回与代码对象 code 关联的新函数对象。 globals 必须是一个字典,该函数可以访问全局变量。
The function’s docstring, name and __module__ are retrieved from the code object, the argument defaults and closure are set to NULL.
-
PyObject*
PyFunction_GetGlobals(PyObject *op)¶ - Return value: Borrowed reference.
返回与函数对象*op*相关联的全局字典。
-
PyObject*
PyFunction_GetModule(PyObject *op)¶ - Return value: Borrowed reference.
返回函数对象 op 的 __module__ 属性,通常为一个包含了模块名称的字符串,但可以通过 Python 代码设为返回其他任意对象。
-
PyObject*
PyFunction_GetDefaults(PyObject *op)¶ - Return value: Borrowed reference.
Return the argument default values of the function object op. This can be a tuple of arguments or NULL.
-
int
PyFunction_SetDefaults(PyObject *op, PyObject *defaults)¶ Set the argument default values for the function object op. defaults must be Py_None or a tuple.
失败时引发
SystemError异常并返回-1。
-
PyObject*
PyFunction_GetClosure(PyObject *op)¶ - Return value: Borrowed reference.
Return the closure associated with the function object op. This can be NULL or a tuple of cell objects.
-
int
PyFunction_SetClosure(PyObject *op, PyObject *closure)¶ Set the closure associated with the function object op. closure must be Py_None or a tuple of cell objects.
失败时引发
SystemError异常并返回-1。
