튜플 객체

type PyTupleObject

PyObject의 서브 형은 파이썬 튜플 객체를 나타냅니다.

PyTypeObject PyTuple_Type
Part of the Stable ABI.

PyTypeObject 인스턴스는 파이썬 튜플 형을 나타냅니다. 파이썬 계층의 tuple과 같은 객체입니다.

int PyTuple_Check(PyObject *p)

p가 튜플 객체이거나 튜플 형의 서브 형의 인스턴스면 참을 돌려줍니다. 이 함수는 항상 성공합니다.

int PyTuple_CheckExact(PyObject *p)

p가 튜플 객체이지만, 튜플 형의 서브 형의 인스턴스는 아니면 참을 돌려줍니다. 이 함수는 항상 성공합니다.

PyObject *PyTuple_New(Py_ssize_t len)
Return value: New reference. Part of the Stable ABI.

크기 len 인 튜플 객체나, 실패 시 NULL을 반환합니다.

PyObject *PyTuple_Pack(Py_ssize_t n, ...)
Return value: New reference. Part of the Stable ABI.

크기 n 인 새 튜플 객체나, 실패 시 NULL을 반환합니다. 튜플 값은 파이썬 객체를 가리키는 후속 n 개의 C 인자로 초기화됩니다. PyTuple_Pack(2, a, b)Py_BuildValue("(OO)", a, b)와 동등합니다.

Py_ssize_t PyTuple_Size(PyObject *p)
Part of the Stable ABI.

튜플 객체에 대한 포인터를 받아서, 해당 튜플의 크기를 반환합니다.

Py_ssize_t PyTuple_GET_SIZE(PyObject *p)

튜플 p의 크기를 반환합니다. 이 크기는 NULL이 아니고 튜플을 가리켜야 합니다; 에러 검사는 수행되지 않습니다.

PyObject *PyTuple_GetItem(PyObject *p, Py_ssize_t pos)
Return value: Borrowed reference. Part of the Stable ABI.

Return the object at position pos in the tuple pointed to by p. If pos is negative or out of bounds, return NULL and set an IndexError exception.

PyObject *PyTuple_GET_ITEM(PyObject *p, Py_ssize_t pos)
Return value: Borrowed reference.

PyTuple_GetItem()와 비슷하지만, 인자를 확인하지 않습니다.

PyObject *PyTuple_GetSlice(PyObject *p, Py_ssize_t low, Py_ssize_t high)
Return value: New reference. Part of the Stable ABI.

Return the slice of the tuple pointed to by p between low and high, or NULL on failure. This is the equivalent of the Python expression p[low:high]. Indexing from the end of the tuple is not supported.

int PyTuple_SetItem(PyObject *p, Py_ssize_t pos, PyObject *o)
Part of the Stable ABI.

p가 가리키는 튜플의 pos 위치에 객체 o에 대한 참조를 삽입합니다. 성공하면 0을 반환합니다. pos가 범위를 벗어나면, -1을 반환하고 IndexError 예외를 설정합니다.

참고

이 함수는 o에 대한 참조를 “훔치고” 영향을 받는 위치에서 튜플에 이미 있는 항목에 대한 참조를 버립니다(discard).

void PyTuple_SET_ITEM(PyObject *p, Py_ssize_t pos, PyObject *o)

PyTuple_SetItem()과 비슷하지만, 에러 검사는 하지 않으며 새로운 튜플을 채울 때*만* 사용해야 합니다.

참고

This function “steals” a reference to o, and, unlike PyTuple_SetItem(), does not discard a reference to any item that is being replaced; any reference in the tuple at position pos will be leaked.

int _PyTuple_Resize(PyObject **p, Py_ssize_t newsize)

튜플 크기를 조정하는 데 사용할 수 있습니다. newsize는 튜플의 새로운 길이가 됩니다. 튜플은 불변이라고 여겨지므로, 객체에 대해 참조가 하나만 있을 때만 사용해야 합니다. 튜플이 코드의 다른 부분에 이미 알려졌으면 이것을 사용하지 마십시오. 튜플은 항상 끝에서 커지거나 줄어듭니다. 이것을 오래된 튜플을 파괴하고 새 튜플을 만드는 것으로 생각하십시오, 단지 더 효율적일 뿐입니다. 성공하면 0을 반환합니다. 클라이언트 코드는, *p의 결괏값이 이 함수를 호출하기 전과 같다고 가정해서는 안 됩니다. *p가 참조하는 객체가 바뀌면 원래 *p는 파괴됩니다. 실패하면, -1을 반환하고, *pNULL로 설정하고, MemoryErrorSystemError를 발생시킵니다.

구조체 시퀀스 객체

구조체 시퀀스(struct sequence) 객체는 namedtuple() 객체의 C 등가물입니다, 즉 어트리뷰트를 통해 항목에 액세스할 수 있는 시퀀스입니다. 구조체 시퀀스를 만들려면, 먼저 특정 구조체 시퀀스 형을 만들어야 합니다.

PyTypeObject *PyStructSequence_NewType(PyStructSequence_Desc *desc)
Return value: New reference. Part of the Stable ABI.

아래에 설명된 desc의 데이터로 새로운 구조체 시퀀스 형을 만듭니다. 결과 형의 인스턴스는 PyStructSequence_New()로 만들 수 있습니다.

void PyStructSequence_InitType(PyTypeObject *type, PyStructSequence_Desc *desc)

desc로 구조체 시퀀스 형 type을 재자리에서 초기화합니다.

int PyStructSequence_InitType2(PyTypeObject *type, PyStructSequence_Desc *desc)

PyStructSequence_InitType와 같지만, 성공하면 0을, 실패하면 -1을 반환합니다.

버전 3.4에 추가.

type PyStructSequence_Desc
Part of the Stable ABI (including all members).

만들 구조체 시퀀스 형의 메타 정보를 포함합니다.

const char *name

Name of the struct sequence type.

const char *doc

Pointer to docstring for the type or NULL to omit.

PyStructSequence_Field *fields

Pointer to NULL-terminated array with field names of the new type.

int n_in_sequence

Number of fields visible to the Python side (if used as tuple).

type PyStructSequence_Field
Part of the Stable ABI (including all members).

Describes a field of a struct sequence. As a struct sequence is modeled as a tuple, all fields are typed as PyObject*. The index in the fields array of the PyStructSequence_Desc determines which field of the struct sequence is described.

const char *name

Name for the field or NULL to end the list of named fields, set to PyStructSequence_UnnamedField to leave unnamed.

const char *doc

Field docstring or NULL to omit.

const char *const PyStructSequence_UnnamedField
Part of the Stable ABI since version 3.11.

이름 없는 상태로 남겨두기 위한 필드 이름의 특수 값.

버전 3.9에서 변경: 형이 char *에서 변경되었습니다.

PyObject *PyStructSequence_New(PyTypeObject *type)
Return value: New reference. Part of the Stable ABI.

PyStructSequence_NewType()으로 만든 type의 인스턴스를 만듭니다.

PyObject *PyStructSequence_GetItem(PyObject *p, Py_ssize_t pos)
Return value: Borrowed reference. Part of the Stable ABI.

p가 가리키는 구조체 시퀀스의 위치 pos에 있는 객체를 돌려줍니다. 범위 검사가 수행되지 않습니다.

PyObject *PyStructSequence_GET_ITEM(PyObject *p, Py_ssize_t pos)
Return value: Borrowed reference.

PyStructSequence_GetItem()과 동등한 매크로.

void PyStructSequence_SetItem(PyObject *p, Py_ssize_t pos, PyObject *o)
Part of the Stable ABI.

구조체 시퀀스 p의 인덱스 pos에 있는 필드를 값 o로 설정합니다. PyTuple_SET_ITEM()과 마찬가지로, 이것은 새로운 인스턴스를 채울 때만 사용해야 합니다.

참고

이 함수는 o에 대한 참조를 “훔칩니다”.

void PyStructSequence_SET_ITEM(PyObject *p, Py_ssize_t *pos, PyObject *o)

Similar to PyStructSequence_SetItem(), but implemented as a static inlined function.

참고

이 함수는 o에 대한 참조를 “훔칩니다”.