문제

I was trying to inherit xrange to enable the target object behaviors of an integer list (iterable and in operator support). But I got the following error message:

TypeError: Error when calling the metaclass bases
    type 'xrange' is not an acceptable base type

What's special of xrange?

Also, probably not related to that question, I noticed xrange has not method __contains__. For in operation, my basic knowledge is, a in A is equivalent to A.contains(a). Am I wrong, or xrange is something different?

I don't know if I should paste these as two separated questions. Appologize ahead.

도움이 되었습니까?

해결책

xrange is implemented in C. As you can see in Tim Peters' post, there should be a convincing use case in order to justify the extra effort needed to allow subclassing of it.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top