__contains__() : Bug or Feature ???

sebastien.lannez at gmail.com sebastien.lannez at gmail.com
Fri Sep 21 09:08:05 EDT 2007


Hi everybody,

I need to overload the operator in and let him
return an object ... It seems it is not a
behavior Python expect :

>>> class A:
...    def __contains__(self,a):
...        return 'yop'
...
>>> a=A()
>>> print 'toto' in a
True
>>> print a.__contains__('toto')
yop

I don't know if it's a bug or a feature but i
really need this overloading and don't know
how to do it ... Furthermore I can't use
a trick of the kind : a |in| b ... because
my overloaded operator must be called by : a in b ...

Is someone could help me ?




More information about the Python-list mailing list