python - i have '__contains__' ,why error -


class a(object):     def a(self):         return true     __contains__=a  b=a() print 2 in b#why error 

__contains__ meant take argument. a doesn't accept argument.

the following example working __contains__:

>>> class a(object): ...     def a(self, item): ...         return true ...     __contains__=a ... >>> b=a() >>> print 2 in b true 

Comments

Popular posts from this blog

ruby - When to use an ORM (Sequel, Datamapper, AR, etc.) vs. pure SQL for querying -

php - PHPDoc: @return void necessary? -

c++ - Convert big endian to little endian when reading from a binary file -