blob: e157df216cfe793a41bc2ef51fc010b34d1a3aac [file] [log] [blame]
Georg Brandl54a3faa2008-01-20 09:30:57 +00001.. highlightlang:: c
2
3.. _slice-objects:
4
5Slice Objects
6-------------
7
8
Georg Brandl60203b42010-10-06 10:11:56 +00009.. c:var:: PyTypeObject PySlice_Type
Georg Brandl54a3faa2008-01-20 09:30:57 +000010
Georg Brandl2aff3352010-10-17 10:59:41 +000011 The type object for slice objects. This is the same as :class:`slice` in the
12 Python layer.
Georg Brandl54a3faa2008-01-20 09:30:57 +000013
14
Georg Brandl60203b42010-10-06 10:11:56 +000015.. c:function:: int PySlice_Check(PyObject *ob)
Georg Brandl54a3faa2008-01-20 09:30:57 +000016
17 Return true if *ob* is a slice object; *ob* must not be *NULL*.
18
19
Georg Brandl60203b42010-10-06 10:11:56 +000020.. c:function:: PyObject* PySlice_New(PyObject *start, PyObject *stop, PyObject *step)
Georg Brandl54a3faa2008-01-20 09:30:57 +000021
22 Return a new slice object with the given values. The *start*, *stop*, and
Jeroen Ruigrok van der Wervenbd875522009-04-26 21:06:15 +000023 *step* parameters are used as the values of the slice object attributes of
24 the same names. Any of the values may be *NULL*, in which case the
25 ``None`` will be used for the corresponding attribute. Return *NULL* if
26 the new object could not be allocated.
Georg Brandl54a3faa2008-01-20 09:30:57 +000027
28
Martin v. Löwisdd590972010-12-11 18:17:22 +000029.. c:function:: int PySlice_GetIndices(PyObject *slice, Py_ssize_t length, Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t *step)
Georg Brandl54a3faa2008-01-20 09:30:57 +000030
31 Retrieve the start, stop and step indices from the slice object *slice*,
Jeroen Ruigrok van der Wervenbd875522009-04-26 21:06:15 +000032 assuming a sequence of length *length*. Treats indices greater than
33 *length* as errors.
Georg Brandl54a3faa2008-01-20 09:30:57 +000034
Jeroen Ruigrok van der Wervenbd875522009-04-26 21:06:15 +000035 Returns 0 on success and -1 on error with no exception set (unless one of
36 the indices was not :const:`None` and failed to be converted to an integer,
37 in which case -1 is returned with an exception set).
Georg Brandl54a3faa2008-01-20 09:30:57 +000038
Georg Brandle6bcc912008-05-12 18:05:20 +000039 You probably do not want to use this function.
Georg Brandl54a3faa2008-01-20 09:30:57 +000040
Martin v. Löwis6d9839d2010-12-11 19:22:04 +000041 .. versionchanged:: 3.2
Georg Brandl18d378d2010-12-11 22:19:34 +000042 The parameter type for the *slice* parameter was ``PySliceObject*``
43 before.
Martin v. Löwis6d9839d2010-12-11 19:22:04 +000044
Georg Brandl54a3faa2008-01-20 09:30:57 +000045
Martin v. Löwisdd590972010-12-11 18:17:22 +000046.. c:function:: int PySlice_GetIndicesEx(PyObject *slice, Py_ssize_t length, Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t *step, Py_ssize_t *slicelength)
Georg Brandl54a3faa2008-01-20 09:30:57 +000047
Georg Brandl60203b42010-10-06 10:11:56 +000048 Usable replacement for :c:func:`PySlice_GetIndices`. Retrieve the start,
Jeroen Ruigrok van der Wervenbd875522009-04-26 21:06:15 +000049 stop, and step indices from the slice object *slice* assuming a sequence of
50 length *length*, and store the length of the slice in *slicelength*. Out
51 of bounds indices are clipped in a manner consistent with the handling of
52 normal slices.
Georg Brandl54a3faa2008-01-20 09:30:57 +000053
54 Returns 0 on success and -1 on error with exception set.
Jeroen Ruigrok van der Wervenbd875522009-04-26 21:06:15 +000055
Martin v. Löwis6d9839d2010-12-11 19:22:04 +000056 .. versionchanged:: 3.2
Georg Brandl18d378d2010-12-11 22:19:34 +000057 The parameter type for the *slice* parameter was ``PySliceObject*``
58 before.