OpenRange¶
OpenRange provides a simple interface for building custom range-like objects for any type that can be represented numerically.
Overview¶
Python’s built-in range is great for generating a list of integers and when iterating over the indices of a sequence. There are times, however, when you’d like a similar interface for non-integer types.
The idea behind OpenRange is to provide a base class that allows for quick implementation of arithmetic progressions for any type that can be represented numerically. For example, you might be interested in a range-like interface for iterating over a datetime.date objects using datetime.timedelta as the step. OpenRange provides an example implementation that does just that:
import datetime
from openrange.dt import DateRange
start_date = datetime.date.today()
end_date = start_date + datetime.timedelta(days=365)
two_weeks = datetime.timedelta(days=14)
# yield datetime.date objects for every 2 weeks, starting today, for a year
for dt_date in DateRange(start_date, end_date, two_weeks):
# ... profit
OpenRange makes implementing these types of classes very simple by providing an easy-to-use abstract base class called BaseRange. See the full Documentation for more info.
Support¶
OpenRange is tested against:
- python 2.7, 3.2, 3.3, 3.4
- pypy and pypy3
Primary development and testing were for python 2.7.
Contribute¶
Contribution is welcome from those who propose new features, have ideas for improvement, or submit bug fixes. Here’s a checklist for contributing to this project:
- Open or respond to an issue to discuss a feature or bug
- Fork the repo on GitHub and start making changes
- Write test(s) for the bug or feature
- Add yourself to CONTRIBUTORS.rst
- Send a pull request