gpt4 book ai didi

python - 你如何在 Python 中继承 Queue

转载 作者:太空宇宙 更新时间:2023-11-03 14:33:19 24 4
gpt4 key购买 nike

当我继承 Queue 时出现错误:

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

当我阅读它时,一些关于经典类(class)等的内容

如何初始化队列基类?

最佳答案

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

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

关于python - 你如何在 Python 中继承 Queue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6714040/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com