我试图继承xrange
以启用整数列表的目标对象行为(可迭代和in
运算符支持)。但我收到以下错误消息:
TypeError: Error when calling the metaclass bases
type 'xrange' is not an acceptable base type
有什么特别之处xrange
?
另外,可能与那个问题无关,我注意到xrange
has not method __contains__
。对于in
操作,我的基本知识是,a in A
相当于A. contains (a)。我错了,还是xrange
有什么不同?
我不知道我是否应该将这些粘贴为两个单独的问题。提前道歉。