Objek Fungsi¶
Terdapat beberapa fungsi spesifik untuk fungsi Python.
-
PyFunctionObject
¶ Struktur C yang digunakan untuk fungsi.
-
PyTypeObject
PyFunction_Type
¶ Ini adalah instance dari
PyTypeObject
dan mewakili jenis fungsi Python. Itu diekspos ke programmer Python sebagaitypes.FunctionType
.
-
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.
Mengembalikan objek fungsi baru yang terkait dengan objek kode code. global harus berupa dictionary dengan variabel global yang dapat diakses oleh fungsi tersebut.
The function's docstring and name are retrieved from the code object. __module__ is retrieved from globals. The argument defaults, annotations and closure are set to NULL. __qualname__ is set to the same value as the function's name.
-
PyObject*
PyFunction_NewWithQualName
(PyObject *code, PyObject *globals, PyObject *qualname)¶ - Return value: New reference.
As
PyFunction_New()
, but also allows setting the function object's__qualname__
attribute. qualname should be a unicode object or NULL; if NULL, the__qualname__
attribute is set to the same value as its__name__
attribute.Baru pada versi 3.3.
-
PyObject*
PyFunction_GetCode
(PyObject *op)¶ - Return value: Borrowed reference.
Mengembalikan objek kode yang terkait dengan objek fungsi op.
-
PyObject*
PyFunction_GetGlobals
(PyObject *op)¶ - Return value: Borrowed reference.
Mengembalikan dictionary global yang terkait dengan objek fungsi op.
-
PyObject*
PyFunction_GetModule
(PyObject *op)¶ - Return value: Borrowed reference.
Mengembalikan atribut __module__ dari objek fungsi op. Ini biasanya berupa string yang berisi nama modul, tetapi dapat diatur ke objek lain dengan kode 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.
Menimbulkan
SystemError
dan mengembalikan-1
jika gagal.
-
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.
Menimbulkan
SystemError
dan mengembalikan-1
jika gagal.
-
PyObject *
PyFunction_GetAnnotations
(PyObject *op)¶ Return the annotations of the function object op. This can be a mutable dictionary or NULL.
-
int
PyFunction_SetAnnotations
(PyObject *op, PyObject *annotations)¶ Set the annotations for the function object op. annotations must be a dictionary or Py_None.
Menimbulkan
SystemError
dan mengembalikan-1
jika gagal.