序列協(xié)議?
-
int PySequence_Check(PyObject *o)?
- Part of the Stable ABI.
Return
1if the object provides the sequence protocol, and0otherwise. Note that it returns1for Python classes with a__getitem__()method, unless they aredictsubclasses, since in general it is impossible to determine what type of keys the class supports. This function always succeeds.
-
Py_ssize_t PySequence_Size(PyObject *o)?
-
Py_ssize_t PySequence_Length(PyObject *o)?
- Part of the Stable ABI.
成功時(shí)返回序列中*o*的對象數,失敗時(shí)返回``-1``. 相當于Python的``len(o)``表達式.
-
PyObject *PySequence_Concat(PyObject *o1, PyObject *o2)?
- Return value: New reference. Part of the Stable ABI.
成功時(shí)返回 o1 和 o2 的拼接,失敗時(shí)返回
NULL。 這等價(jià)于 Python 表達式o1 + o2。
-
PyObject *PySequence_Repeat(PyObject *o, Py_ssize_t count)?
- Return value: New reference. Part of the Stable ABI.
返回序列對象 o 重復 count 次的結果,失敗時(shí)返回
NULL。 這等價(jià)于 Python 表達式o * count。
-
PyObject *PySequence_InPlaceConcat(PyObject *o1, PyObject *o2)?
- Return value: New reference. Part of the Stable ABI.
成功時(shí)返回 o1 和 o2 的拼接,失敗時(shí)返回
NULL。 在 o1 支持的情況下操作將 原地 完成。 這等價(jià)于 Python 表達式o1 += o2。
-
PyObject *PySequence_InPlaceRepeat(PyObject *o, Py_ssize_t count)?
- Return value: New reference. Part of the Stable ABI.
Return the result of repeating sequence object返回序列對象 o 重復 count 次的結果,失敗時(shí)返回
NULL。 在 o 支持的情況下該操作會(huì ) 原地 完成。 這等價(jià)于 Python 表達式o *= count。
-
PyObject *PySequence_GetItem(PyObject *o, Py_ssize_t i)?
- Return value: New reference. Part of the Stable ABI.
返回 o 中的第 i 號元素,失敗時(shí)返回
NULL。 這等價(jià)于 Python 表達式o[i]。
-
PyObject *PySequence_GetSlice(PyObject *o, Py_ssize_t i1, Py_ssize_t i2)?
- Return value: New reference. Part of the Stable ABI.
返回序列對象 o 的 i1 到 i2 的切片,失敗時(shí)返回
NULL。 這等價(jià)于 Python 表達式o[i1:i2]。
-
int PySequence_SetItem(PyObject *o, Py_ssize_t i, PyObject *v)?
- Part of the Stable ABI.
將對象 v 賦值給 o 的第 i 號元素。 失敗時(shí)會(huì )引發(fā)異常并返回
-1;成功時(shí)返回0。 這相當于 Python 語(yǔ)句o[i] = v。 此函數 不會(huì ) 改變對 v 的引用。If v is
NULL, the element is deleted, but this feature is deprecated in favour of usingPySequence_DelItem().
-
int PySequence_DelItem(PyObject *o, Py_ssize_t i)?
- Part of the Stable ABI.
刪除對象 o 的第 i 號元素。 失敗時(shí)返回
-1。 這相當于 Python 語(yǔ)句del o[i]。
-
int PySequence_SetSlice(PyObject *o, Py_ssize_t i1, Py_ssize_t i2, PyObject *v)?
- Part of the Stable ABI.
將序列對象 v 賦值給序列對象 o 的從 i1 到 i2 切片。 這相當于 Python 語(yǔ)句
o[i1:i2] = v。
-
int PySequence_DelSlice(PyObject *o, Py_ssize_t i1, Py_ssize_t i2)?
- Part of the Stable ABI.
刪除序列對象 o 的從 i1 到 i2 的切片。 失敗時(shí)返回
-1。 這相當于 Python 語(yǔ)句del o[i1:i2]。
-
Py_ssize_t PySequence_Count(PyObject *o, PyObject *value)?
- Part of the Stable ABI.
返回 value 在 o 中出現的次數,即返回使得
o[key] == value的鍵的數量。 失敗時(shí)返回-1。 這相當于 Python 表達式o.count(value)。
-
int PySequence_Contains(PyObject *o, PyObject *value)?
- Part of the Stable ABI.
確定 o 是否包含 value。 如果 o 中的某一項等于 value,則返回
1,否則返回0。 出錯時(shí),返回-1。 這相當于 Python 表達式value in o。
-
Py_ssize_t PySequence_Index(PyObject *o, PyObject *value)?
- Part of the Stable ABI.
返回第一個(gè)索引*i*,其中
o[i] == value.出錯時(shí),返回-1.相當于Python的``o.index(value)``表達式.
-
PyObject *PySequence_List(PyObject *o)?
- Return value: New reference. Part of the Stable ABI.
返回一個(gè)列表對象,其內容與序列或可迭代對象 o 相同,失敗時(shí)返回
NULL。 返回的列表保證是一個(gè)新對象。 這等價(jià)于 Python 表達式list(o)。
-
PyObject *PySequence_Tuple(PyObject *o)?
- Return value: New reference. Part of the Stable ABI.
返回一個(gè)元組對象,其內容與序列或可迭代對象 o 相同,失敗時(shí)返回
NULL。 如果 o 為元組,則將返回一個(gè)新的引用,在其他情況下將使用適當的內容構造一個(gè)元組。 這等價(jià)于 Python 表達式tuple(o)。
-
PyObject *PySequence_Fast(PyObject *o, const char *m)?
- Return value: New reference. Part of the Stable ABI.
將序列或可迭代對象 o 作為其他
PySequence_Fast*函數族可用的對象返回。 如果該對象不是序列或可迭代對象,則會(huì )引發(fā)TypeError并將 m 作為消息文本。 失敗時(shí)返回NULL。PySequence_Fast*函數之所以這樣命名,是因為它們會(huì )假定 o 是一個(gè)PyTupleObject或PyListObject并直接訪(fǎng)問(wèn) o 的數據字段。作為 CPython 的實(shí)現細節,如果 o 已經(jīng)是一個(gè)序列或列表,它將被直接返回。
-
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 notNULL. The size can also be retrieved by callingPySequence_Size()on o, butPySequence_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.
在 o 由
PySequence_Fast()返回且 o 不NULL,并且 i d在索引范圍內的情況下返回 o 的第 i 號元素。
-
PyObject **PySequence_Fast_ITEMS(PyObject *o)?
返回 PyObject 指針的底層數組。 假設 o 由
PySequence_Fast()返回且 o 不為NULL。請注意,如果列表調整大小,重新分配可能會(huì )重新定位items數組.因此,僅在序列無(wú)法更改的上下文中使用基礎數組指針.
-
PyObject *PySequence_ITEM(PyObject *o, Py_ssize_t i)?
- Return value: New reference.
返回 o 的第 i 個(gè)元素或在失敗時(shí)返回
NULL。 此形式比PySequence_GetItem()理饌,但不會(huì )檢查 o 上的PySequence_Check()是否為真值,也不會(huì )對負序號進(jìn)行調整。