튜플 객체

type PyTupleObject

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

PyTypeObject PyTuple_Type
Part of the 안정 ABI.

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

int PyTuple_Check(PyObject *p)

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

int PyTuple_CheckExact(PyObject *p)

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

PyObject *PyTuple_New(Py_ssize_t len)
반환값: 새 참조. Part of the 안정 ABI. Thread safety: Atomic.

크기 len 인 튜플 객체나, 실패 시 예외를 설정하고 NULL을 반환합니다.

PyObject *PyTuple_FromArray(PyObject *const *array, Py_ssize_t size)
Thread safety: Atomic.

Create a tuple of size items and copy references from array to the new tuple.

array can be NULL if size is 0.

On success, return a new reference. On error, set an exception and return NULL.

Added in version 3.15.

PyObject *PyTuple_Pack(Py_ssize_t n, ...)
반환값: 새 참조. Part of the 안정 ABI. Thread safety: Atomic.

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

Py_ssize_t PyTuple_Size(PyObject *p)
Part of the 안정 ABI. Thread safety: Atomic.

Take a pointer to a tuple object, and return the size of that tuple. On error, return -1 with an exception set.

Py_ssize_t PyTuple_GET_SIZE(PyObject *p)
Thread safety: Atomic.

PyTuple_Size()와 비슷하지만, 에러 검사를 생략합니다.

PyObject *PyTuple_GetItem(PyObject *p, Py_ssize_t pos)
반환값: 빌린 참조. Part of the 안정 ABI. Thread safety: Safe to call from multiple threads with external synchronization only.

p가 가리키는 튜플의 pos 위치에 있는 객체를 반환합니다. pos가 음수이거나 범위를 벗어나면, NULL을 반환하고 IndexError 예외를 설정합니다.

The returned reference is borrowed from the tuple p (that is: it is only valid as long as you hold a reference to p). To get a strong reference, use Py_NewRef(PyTuple_GetItem(...)) or PySequence_GetItem().

PyObject *PyTuple_GET_ITEM(PyObject *p, Py_ssize_t pos)
반환값: 빌린 참조. Thread safety: Safe to call from multiple threads with external synchronization only.

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

PyObject *PyTuple_GetSlice(PyObject *p, Py_ssize_t low, Py_ssize_t high)
반환값: 새 참조. Part of the 안정 ABI. Thread safety: Atomic.

p가 가리키는 튜플의 lowhigh 사이의 슬라이스를 반환하거나, 실패하면 예외를 설정하고 NULL을 반환합니다.

이것은 파이썬 표현식 p[low:high]와 동등합니다. 튜플 끝으로부터의 인덱싱은 지원되지 않습니다.

int PyTuple_SetItem(PyObject *p, Py_ssize_t pos, PyObject *o)
Part of the 안정 ABI. Thread safety: Safe to call from multiple threads with external synchronization only.

Insert a reference to object o at position pos of the tuple pointed to by p. Return 0 on success. If pos is out of bounds, return -1 and set an IndexError exception. This function should only be used to fill in brand new tuples; using it on an existing tuple is thread-unsafe.

참고

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

void PyTuple_SET_ITEM(PyObject *p, Py_ssize_t pos, PyObject *o)
Thread safety: Safe to call from multiple threads with external synchronization only.

Like PyTuple_SetItem(), but does no error checking, and should only be used to fill in brand new tuples, using it on an existing tuple is thread-unsafe.

Bounds checking is performed as an assertion if Python is built in debug mode or with assertions.

참고

이 함수는 o에 대한 참조를 “훔치고”, PyTuple_SetItem()와 달리, 교체 중인 항목에 대한 참조를 버리지 않습니다; pos 위치에서 튜플의 모든 참조는 누수됩니다.

경고

This macro should only be used on tuples that are newly created. Using this macro on a tuple that is already in use (or in other words, has a refcount > 1) could lead to undefined behavior.

int _PyTuple_Resize(PyObject **p, Py_ssize_t newsize)
Thread safety: Safe to call from multiple threads with external synchronization only.

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

구조체 시퀀스 객체

A struct sequence object is a named tuple, that is, a sequence whose items can also be accessed through attributes. It is similar to collections.namedtuple(), but provides a slightly different interface.

To create a struct sequence, you first have to create a specific struct sequence type.

PyTypeObject *PyStructSequence_NewType(PyStructSequence_Desc *desc)
반환값: 새 참조. Part of the 안정 ABI. Thread safety: Atomic.

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

실패 시 예외를 설정하고 NULL을 반환합니다.

void PyStructSequence_InitType(PyTypeObject *type, PyStructSequence_Desc *desc)
Thread safety: Safe to call without external synchronization on distinct objects.

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

int PyStructSequence_InitType2(PyTypeObject *type, PyStructSequence_Desc *desc)
Thread safety: Safe to call without external synchronization on distinct objects.

PyStructSequence_InitType()와 비슷하지만, 성공하면 0을, 실패하면 예외를 설정하고 -1을 반환합니다.

Added in version 3.4.

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

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

const char *name

Fully qualified name of the type; null-terminated UTF-8 encoded. The name must contain the module name.

const char *doc

해당 형에 대한 독스트링에 대한 포인터나 생략하려면 NULL.

PyStructSequence_Field *fields

새로운 형의 필드 이름을 가진 NULL로 끝나는 배열에 대한 포인터.

int n_in_sequence

파이썬 측에서 볼 수 있는 필드 수 (튜플로 사용된 경우).

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

구조체 시퀀스의 필드를 기술합니다. 구조체 시퀀스는 튜플로 모형화되므로, 모든 필드는 PyObject* 형을 취합니다. PyStructSequence_Descfields 배열의 인덱스는 구조체 시퀀스의 어떤 필드가 기술되는지를 결정합니다.

const char *name

필드의 이름. 또는 이름있는 필드의 목록을 끝내려면 NULL, 이름이 없는 상태로 두려면 PyStructSequence_UnnamedField로 설정합니다.

const char *doc

필드 독스트링이나 생략하려면 NULL.

const char *const PyStructSequence_UnnamedField
Part of the 안정 ABI 버전 3.11 이후로.

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

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

PyObject *PyStructSequence_New(PyTypeObject *type)
반환값: 새 참조. Part of the 안정 ABI. Thread safety: Atomic.

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

실패 시 예외를 설정하고 NULL을 반환합니다.

PyObject *PyStructSequence_GetItem(PyObject *p, Py_ssize_t pos)
반환값: 빌린 참조. Part of the 안정 ABI. Thread safety: Safe to call from multiple threads with external synchronization only.

Return the object at position pos in the struct sequence pointed to by p. The returned reference is borrowed from the struct sequence p (that is: it is only valid as long as you hold a reference to p).

Bounds checking is performed as an assertion if Python is built in debug mode or with assertions.

PyObject *PyStructSequence_GET_ITEM(PyObject *p, Py_ssize_t pos)
반환값: 빌린 참조. Thread safety: Safe to call from multiple threads with external synchronization only.

PyStructSequence_GetItem()의 별칭.

버전 3.13에서 변경: 이제 PyStructSequence_GetItem()의 별칭으로 구현됩니다.

void PyStructSequence_SetItem(PyObject *p, Py_ssize_t pos, PyObject *o)
Part of the 안정 ABI. Thread safety: Safe to call from multiple threads with external synchronization only.

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

Bounds checking is performed as an assertion if Python is built in debug mode or with assertions.

참고

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

void PyStructSequence_SET_ITEM(PyObject *p, Py_ssize_t *pos, PyObject *o)
Thread safety: Safe to call from multiple threads with external synchronization only.

PyStructSequence_SetItem()의 별칭.

버전 3.13에서 변경: 이제 PyStructSequence_SetItem()의 별칭으로 구현됩니다.