作者chmate ([][][])
看板Python
标题Re: [问题] membership test
时间Mon Mar 31 22:31:02 2008
※ 引述《huggie (huggie)》之铭言:
: 我自订了一个 class ..里面有个 dictionary 的 member
: 对 dictionary inheritance 不熟,贪快所以直接用包的。
: __getitem__ 可以用来做 index
: 我就用来 proxy (是这样称呼吗) 里面的那个 dictionary
: 但是 membership test 好像不能用 (例如 'xxx' in dic)
: 明明没有在 dictionary 里面居然 pass 了
: 请问要怎麽用?
http://docs.python.org/ref/comparisons.html
For user-defined classes which define the __contains__() method, x in y is
true if and only if y.__contains__(x) is true.
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 220.143.225.229
1F:推 huggie:3Q 03/31 23:03