【问题标题】:how do you inherit Queue in Python你如何在 Python 中继承队列
【发布时间】:2011-07-15 23:01:49
【问题描述】:

当我继承队列时,我得到一个错误:

super(domainQueue,self).__init__()
TypeError: must be type, not classobj

当我阅读它时,一些关于经典课程等的东西。

如何初始化 Queue 基类?

【问题讨论】:

    标签: python queue python-2.7


    【解决方案1】:

    Queue.Queue 是一个老式类,因此它不支持许多新式类的特性(例如super)。您有两种选择,即按照 TorelTwiddler 的回答中的建议显式调用 Queue.Queue,或者将 object 添加到基础:

    class myQueue(Queue.Queue, object):
        def __init__(self):
            super(myQueue, self).__init__()
    

    【讨论】:

      【解决方案2】:

      要让它正常工作,请改用Queue.__init__(self)

      class myQueue(Queue.Queue):
          def __init__(self):
              Queue.Queue.__init__(self)
      

      为什么它返回 classobj 而不是 type?不知道。

      【讨论】:

      • 当我使用 init 函数时,由于没有 init 函数而失败
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多