On 2021-08-12 at 08:56:22 -0000, eloi.riv...@aquilenet.fr wrote: > Hi. I am working on a kinda-ORM library, which usage often implies to request > data within specific ranges: > > Foobar.search( > attr1="foo", > attr2=gt(10), > attr3=between(42, 50) > ) > > The use of "gt" or "between" methods to describe those operations feels a bit > cumbersome (as it is long to write, and you need to import those functions in > a lot of files), and I though it could be more pythonic to use slices instead. > > Foobar.search( > attr1="foo", > attr2=slice(10), > attr3=slice(42, 50) > ) > > I suggest an alternative way to instanciate slices, that would look like this: > > Foobar.search( > attr1="foo", > attr2=[10:], > attr3=[42:50] > ) > > What do you think?
I think there will be a lot of off-by-1 errors. BETWEEN is inclusive on both ends. BETWEEN 42 AND 50 includes records where the value is 50. Python slices are open ended intervals. slice(42, 50) would *not* include the value 50. That tells me that slices are *not* a good substitute for BETWEEN when it comes to database queries. _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/HDXSMLLD3NZ7UN2KF6J4PMSYP4HZFU2E/ Code of Conduct: http://python.org/psf/codeofconduct/