5.1.1.10.10. Slice¶
This module implements interval arithmetic for flat [1] and line slice.
| [1] | Flat indexes address characters in a file. |
-
class
CodeReview.Tools.Slice.FlatSlice(*args)[source]¶ Bases:
CodeReview.Tools.Slice.SliceThis class defines a flat slice.
-
class
CodeReview.Tools.Slice.LineSlice(*args)[source]¶ Bases:
CodeReview.Tools.Slice.SliceThis class defines a line slice.
-
class
CodeReview.Tools.Slice.Slice(*args)[source]¶ Bases:
objectThis class implements a generic slice.
Like for a standard Python slice, a
Sliceinstance is built from two values or an indexable object providing the start and stop value. This class implements an array interface (__getitem__()method) so as to pass aSliceinstance to the constructor. Some examples to build a slice:slice1 = Slice(1, 2) slice2 = Slice((1, 2)) slice2 = Slice([1, 2]) slice3 = Slice(slice2)
The interval limits of the slice can be accessed using the
start,stop,lowerandupperread-only attributes, upper is defined as stop -1.To cast an instance to a standard Python slice use the call:
slice()
To get the length of the slice defined by stop - start use the
len()function.A slice is not empty if it verifies the predicate stop > start, this predicate can be tested using a Boolean evaluation of the instance.
A slice can be scaled by a factor using:
slice // 2 slice //= 2
The union and the intersection of two slices can be computed using:
# union slice1 |= slice2 slice = slice1 | slice2 # intersection slice1 &= slice2 slice = slice1 & slice2
-
lower¶ Lower boundary.
-
start¶ Start boundary.
-
stop¶ Stop boundary.
-
upper¶ Upper boundary.
-