함수 객체¶
파이썬 함수와 관련된 몇 가지 함수가 있습니다.
-
PyFunctionObject¶ 함수에 사용되는 C 구조체.
-
PyTypeObject
PyFunction_Type¶ 이것은
PyTypeObject의 인스턴스이며 파이썬 함수 형을 나타냅니다. 파이썬 프로그래머에게types.FunctionType으로 노출됩니다.
-
int
PyFunction_Check(PyObject *o)¶ Return true if o is a function object (has type
PyFunction_Type). The parameter must not beNULL.
-
PyObject*
PyFunction_New(PyObject *code, PyObject *globals)¶ - Return value: New reference.
코드 객체 code와 연관된 새 함수 객체를 반환합니다. globals는 함수에서 액세스할 수 있는 전역 변수가 있는 딕셔너리이어야 합니다.
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 orNULL; ifNULL, the__qualname__attribute is set to the same value as its__name__attribute.버전 3.3에 추가.
-
PyObject*
PyFunction_GetCode(PyObject *op)¶ - Return value: Borrowed reference.
함수 객체 op와 연관된 코드 객체를 반환합니다.
-
PyObject*
PyFunction_GetGlobals(PyObject *op)¶ - Return value: Borrowed reference.
함수 객체 op와 연관된 전역 딕셔너리를 반환합니다.
-
PyObject*
PyFunction_GetModule(PyObject *op)¶ - Return value: Borrowed reference.
함수 객체 op의 __module__ 어트리뷰트를 반환합니다. 이것은 일반적으로 모듈 이름을 포함하는 문자열이지만, 파이썬 코드로 다른 객체로 설정할 수 있습니다.
-
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_Noneor 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
NULLor 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_Noneor a tuple of cell objects.실패하면
SystemError를 발생시키고-1을 반환합니다.
-
PyObject *
PyFunction_GetAnnotations(PyObject *op)¶ - Return value: Borrowed reference.
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.실패하면
SystemError를 발생시키고-1을 반환합니다.
