Skip to main content

A small flexible interval package

Project description

pynterval

A small python module to handle numeric intervals

pip install pynterval
>>> from pynterval import Interval
>>> 
>>> my_interval = Interval(0, 5)
>>> vals = (0, 4, 5, Interval(2.1, 3.4), Interval(0, 5), Interval(0, 5, 3))
>>> [val in my_interval for val in vals]
[True, True, False, True, True, False]
>>> 
>>> Interval()
Interval: {}
>>> Interval().empty
True
>>> Interval(4)
Interval: {4}

*** Works also with many other comparable objects ***

>>> from pynterval import Interval
>>> import pint
>>> ureg = pint.UnitRegistry()
>>> 
>>> my_interval = Interval(0 * ureg.mm, 15 * ureg.cm)
>>> (1 * ureg.inch) in my_interval
True
>>> 
>>> my_rightunbounded_interval = Interval(100 * ureg.mm, float('inf'))
>>> (5 * ureg.cm) in my_rightunbounded_interval
False
>>> (5 * ureg.lightyear) in my_rightunbounded_interval
True

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pynterval-0.3.tar.gz (6.7 kB view hashes)

Uploaded Source

Built Distribution

pynterval-0.3-py3-none-any.whl (6.9 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page