Slice Objects¶
- PyTypeObject
PySlice_Type¶ The type object for slice objects. This is the same as
slicein thePython layer.
- PyObject*
PySlice_New(PyObject *start,PyObject *stop,PyObject *step)¶ - Return value: New reference.
Return a new slice object with the given values. Thestart,stop, andstep parameters are used as the values of the slice object attributes ofthe same names. Any of the values may beNULL, in which case the
Nonewill be used for the corresponding attribute. ReturnNULL ifthe new object could not be allocated.
- int
PySlice_GetIndices(PyObject *slice, Py_ssize_t length, Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t *step)¶ Retrieve the start, stop and step indices from the slice objectslice,assuming a sequence of lengthlength. Treats indices greater thanlength as errors.
Returns
0on success and-1on error with no exception set (unless one ofthe indices was notNoneand failed to be converted to an integer,in which case-1is returned with an exception set).You probably do not want to use this function.
Changed in version 3.2:The parameter type for theslice parameter was
PySliceObject*before.
- 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)¶ Usable replacement for
PySlice_GetIndices(). Retrieve the start,stop, and step indices from the slice objectslice assuming a sequence oflengthlength, and store the length of the slice inslicelength. Outof bounds indices are clipped in a manner consistent with the handling ofnormal slices.Returns
0on success and-1on error with exception set.Changed in version 3.2:The parameter type for theslice parameter was
PySliceObject*before.
