[Python-ideas] Implement comparison operators for range objects
Ron Adam
ron3200 at gmail.com
Wed Oct 12 18:50:23 CEST 2011
On Wed, 2011-10-12 at 17:31 +0100, Sven Marnach wrote:
> There are circumstances, for example in unit testing, when it might be
> useful to check if two range objects describe the same range.
> Currently, this can't be done using the '==' operator:
>
> >>> range(5) == range(5)
> False
Would comparing the repr of each one work?
>>> r1 = range(5)
>>> r2 = range(5)
>>> r1 == r2
False
>>> repr(r1), repr(r2)
('range(0, 5)', 'range(0, 5)')
>>> repr(r1) == repr(r2)
True
Cheers,
Ron
More information about the Python-ideas
mailing list