简体   繁体   中英

Reason why xrange is not inheritable in Python?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM