시퀀스 프로토콜

int PySequence_Check(PyObject *o)

객체가 시퀀스 프로토콜을 제공하면 1을 반환하고, 그렇지 않으면 0을 반환합니다. __getitem__() 메서드가 있는 파이썬 클래스의 경우 dict 서브 클래스가 아닌 한 1을 반환하는 것에 유의하십시오. 일반적으로 어떤 형의 키를 지원하는지 판단할 수 없기 때문입니다. 이 함수는 항상 성공합니다.

Py_ssize_t PySequence_Size(PyObject *o)
Py_ssize_t PySequence_Length(PyObject *o)

성공 시 시퀀스 o의 객체 수를 반환하고, 실패하면 -1을 반환합니다. 이것은 파이썬 표현식 len(o)와 동등합니다.

PyObject* PySequence_Concat(PyObject *o1, PyObject *o2)
Return value: New reference.

Return the concatenation of o1 and o2 on success, and NULL on failure. This is the equivalent of the Python expression o1 + o2.

PyObject* PySequence_Repeat(PyObject *o, Py_ssize_t count)
Return value: New reference.

Return the result of repeating sequence object o count times, or NULL on failure. This is the equivalent of the Python expression o * count.

PyObject* PySequence_InPlaceConcat(PyObject *o1, PyObject *o2)
Return value: New reference.

Return the concatenation of o1 and o2 on success, and NULL on failure. The operation is done in-place when o1 supports it. This is the equivalent of the Python expression o1 += o2.

PyObject* PySequence_InPlaceRepeat(PyObject *o, Py_ssize_t count)
Return value: New reference.

Return the result of repeating sequence object o count times, or NULL on failure. The operation is done in-place when o supports it. This is the equivalent of the Python expression o *= count.

PyObject* PySequence_GetItem(PyObject *o, Py_ssize_t i)
Return value: New reference.

Return the ith element of o, or NULL on failure. This is the equivalent of the Python expression o[i].

PyObject* PySequence_GetSlice(PyObject *o, Py_ssize_t i1, Py_ssize_t i2)
Return value: New reference.

Return the slice of sequence object o between i1 and i2, or NULL on failure. This is the equivalent of the Python expression o[i1:i2].

int PySequence_SetItem(PyObject *o, Py_ssize_t i, PyObject *v)

객체 voi 번째 요소에 대입합니다. 실패하면 예외를 발생시키고 -1을 반환합니다; 성공하면 0을 반환합니다. 이것은 파이썬 문장 o[i] = v와 동등합니다. 이 함수는 v에 대한 참조를 훔치지 않습니다.

If v is NULL, the element is deleted, however this feature is deprecated in favour of using PySequence_DelItem().

int PySequence_DelItem(PyObject *o, Py_ssize_t i)

o 객체의 i 번째 요소를 삭제합니다. 실패하면 -1을 반환합니다. 이것은 파이썬 문장 del o[i]와 동등합니다.

int PySequence_SetSlice(PyObject *o, Py_ssize_t i1, Py_ssize_t i2, PyObject *v)

시퀀스 객체 v를 시퀀스 객체 oi1에서 i2 사이의 슬라이스에 대입합니다. 이것은 파이썬 문장 o[i1:i2] = v와 동등합니다.

int PySequence_DelSlice(PyObject *o, Py_ssize_t i1, Py_ssize_t i2)

시퀀스 객체 oi1에서 i2 사이의 슬라이스를 삭제합니다. 실패하면 -1을 반환합니다. 이것은 파이썬 문장 del o[i1:i2]와 동등합니다.

Py_ssize_t PySequence_Count(PyObject *o, PyObject *value)

o에 있는 value의 수를 반환합니다. 즉, o[key] == value를 만족하는 key의 수를 반환합니다. 실패하면 -1을 반환합니다. 이것은 파이썬 표현식 o.count(value)와 동등합니다.

int PySequence_Contains(PyObject *o, PyObject *value)

ovalue가 있는지 확인합니다. o의 항목 중 하나가 value와 같으면 1을 반환하고, 그렇지 않으면 0을 반환합니다. 에러 시 -1을 반환합니다. 이는 파이썬 표현식 value in o와 동등합니다.

Py_ssize_t PySequence_Index(PyObject *o, PyObject *value)

o[i] == value을 만족하는 첫 번째 인덱스 i를 반환합니다. 에러 시 -1을 반환합니다. 이것은 파이썬 표현식 o.index(value)와 동등합니다.

PyObject* PySequence_List(PyObject *o)
Return value: New reference.

Return a list object with the same contents as the sequence or iterable o, or NULL on failure. The returned list is guaranteed to be new. This is equivalent to the Python expression list(o).

PyObject* PySequence_Tuple(PyObject *o)
Return value: New reference.

Return a tuple object with the same contents as the sequence or iterable o, or NULL on failure. If o is a tuple, a new reference will be returned, otherwise a tuple will be constructed with the appropriate contents. This is equivalent to the Python expression tuple(o).

PyObject* PySequence_Fast(PyObject *o, const char *m)
Return value: New reference.

Return the sequence or iterable o as an object usable by the other PySequence_Fast* family of functions. If the object is not a sequence or iterable, raises TypeError with m as the message text. Returns NULL on failure.

The PySequence_Fast* functions are thus named because they assume o is a PyTupleObject or a PyListObject and access the data fields of o directly.

As a CPython implementation detail, if o is already a sequence or list, it will be returned.

Py_ssize_t PySequence_Fast_GET_SIZE(PyObject *o)

Returns the length of o, assuming that o was returned by PySequence_Fast() and that o is not NULL. The size can also be gotten by calling PySequence_Size() on o, but PySequence_Fast_GET_SIZE() is faster because it can assume o is a list or tuple.

PyObject* PySequence_Fast_GET_ITEM(PyObject *o, Py_ssize_t i)
Return value: Borrowed reference.

Return the ith element of o, assuming that o was returned by PySequence_Fast(), o is not NULL, and that i is within bounds.

PyObject** PySequence_Fast_ITEMS(PyObject *o)

Return the underlying array of PyObject pointers. Assumes that o was returned by PySequence_Fast() and o is not NULL.

리스트의 크기가 변경되면, 재할당이 항목 배열을 재배치할 수 있음에 유의하십시오. 따라서, 시퀀스가 변경될 수 없는 문맥에서만 하부 배열 포인터를 사용하십시오.

PyObject* PySequence_ITEM(PyObject *o, Py_ssize_t i)
Return value: New reference.

Return the ith element of o or NULL on failure. Faster form of PySequence_GetItem() but without checking that PySequence_Check() on o is true and without adjustment for negative indices.