开发者

Python bizarre class problem

开发者 https://www.devze.com 2023-01-16 02:52 出处:网络
I have the f开发者_如何学Pythonollowing piece of code where I try to override a method: import Queue

I have the f开发者_如何学Pythonollowing piece of code where I try to override a method:

import Queue
class PriorityQueue(Queue.PriorityQueue):
    def put(self, item):
        super(PriorityQueue, self).put((item.priority, item))

However, when I run it I get TypeError exception:

super() argument 1 must be type, not classobj

What is the problem?


Queue.PriorityQueue is not a new-style class, and super only works with new-style classes. You must use

import Queue
class PriorityQueue(Queue.PriorityQueue):
    def put(self, item):
        Queue.PriorityQueue.put(self,(item.priority, item))

instead.

0

精彩评论

暂无评论...
验证码 换一张
取 消