sqlstring -- a library to build a SELECT statement
Jason Stitt
jason at pengale.com
Thu Oct 20 10:02:34 EDT 2005
On Oct 20, 2005, at 2:19 AM, Steve Holden 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.)
>>
>>>> class inplus(object):
>>>>
> ... def __contains__(self, thing):
> ... print "Do I have a", thing, "?"
> ... return True
> ...
I stand corrected. <excuse>Python.org was intermittently down
yesterday</excuse> so I was trying to play around with the
interactive interpreter and missed it.
For future reference:
http://www.python.org/doc/ref/specialnames.html
However 'in' seems to coerce the return value of __contains__ to True
or False, even if you return an object reference.
- Jason
More information about the Python-list
mailing list