API

BaseRange

Create custom arithmetic progression classes.

class openrange.base.BaseRange(*args)

Bases: _abcoll.Sequence

Abstract base class for custom arithmetic progressions.

Subclasses need only define how to convert between the type of objects within the progression and an underlying numeric type. To do so, these abstract methods must be implemented:

_item_to_num(self, item) _num_to_item(self, num)

In some cases, the step type may differ from the items within the progression. In this case, a subclass should implement the following conversion methods:

_step_to_num(self, step) _num_to_step(self, num)

The default implementations of these step conversion methods assume the start, stop, and step are of the same type and therefore call the abstract _item_to_num() and _num_to_item() methods.

count(item)

Returns the number of times item appears in the progression.

enumerate(start=0)

Generates tuples for each item in the progression.

The tuples yielded take the form (count, item). Count starts at 0 unless an optional keyword argument ‘start’ is supplied with an alternate start value.

excluding(iterable)

Iterate over progression excluding items in supplied iterable.

index(item)

Returns the index of the first item matching the supplied item.

random()

Generate the items in the progression in a random order.

repeat(times=2)

Iterate over the progression multiple times in sequence.

reverse()

Reverses the range in place.

start

The start item for this range.

step

The step item for this range.

stop

The stop item for this range.

Range

class openrange.rng.Range(*args)

Bases: openrange.base.BaseRange

Inclusive numerical range.

datetime Ranges

class openrange.dt.DateRange(start, stop, step)

Bases: openrange.base.BaseRange

Date object progression.

class openrange.dt.DatetimeRange(start, stop, step)

Bases: openrange.base.BaseRange

Datetime object progression.

class openrange.dt.TimeRange(start, stop, step)

Bases: openrange.base.BaseRange

Time object progression.