sqlstring -- a library to build a SELECT statement

Jason Stitt jason at pengale.com
Thu Oct 20 16:52:45 CEST 2005

On Oct 19, 2005, at 11:55 PM, grunar at gmail.com wrote:

> Jason Stitt wrote:
>> Using // for 'in' looks really weird, too. It's too bad you can't
>> overload Python's 'in' operator. (Can you? It seems to be hard-coded
>> to iterate through an iterable and look for the value, rather than
>> calling a private method like some other builtins do.)
> // was a bit of a stretch.  I'd initially thought it for the "where"
> clause, becuase it's lower precedence than ** (I think), and really
> late at night // kind of looks like a W.  I decided against it because
> it looks to close to a comment in some other languages.
> Python "in" clause doesn't seem exploitable in any way--probably a  
> good
> thing.  I did add a "in_" method (name is arguable), which does the
> same thing, also a not_in.

What about modifying the overloaded == to produce 'in' if the right- 
hand side is a list? Then you can more easily generate statements  

def makeCond(name):
     return someOtherCond & (model.table.name == name)

makeCond(["foo", "bar"])

And it doesn't require two different functions.

As long as there is no case where you might actually want to test if  
a column value equals a list, it should work. Is there? Some DBs  
support an Array type, but in general that might be better handled  
with an Array class, anyway.

- Jason, fingers crossed that all this black magic doesn't affect  
one's chances in the afterlife ;)

More information about the Python-list mailing list