python - 子类化双端队列时如何设置 maxlen

标签 python subclass deque

我正在尝试对双端队列进行子类化,但无法弄清楚如何设置 maxlen。

__maxlen__吗?

编辑:-以下是“坏”Python吗?

from collections import deque

class MinMax(deque):
    def __init__(self):
        deque.__init__(self, maxlen=2)

mm = MinMax()

最佳答案

您应该正确调用 super() 构造函数

class dequePlus(collections.deque):
    def __init__(self, iterable):
        super(dequePlus, self).__init__(iterable, 100)

关于python - 子类化双端队列时如何设置 maxlen,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10143578/

相关文章:

java 。用户的输入通过实例变量在主类中起作用,但在其他类中不起作用

python - mysql-connector-python InterfaceError : Failed getting warnings when executing a query with multiple statements with get_warnings=True

python - Django REST Framework 和 MongoEngine 的 AttributeError

python - CTRL-C 导致 forrtl : error (200) rather than python KeyboardInterrupt exception

python - 从 setup.py 安装 sphinx 编译文档

python - 如何继承 ABCMeta

subclass - 在 Python 中重新分类实例

c++ - std::deque、引用和 'pop'

c++ - std::deque 内存使用

c++ - 有没有办法将双端队列的内部存储大小作为 vector::capacity?