Python class problem

I have the following code snippet in which I am trying 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 an exception TypeError:

super() argument 1 must be type, not classobj

What is the problem?

+5
source share
1 answer

Queue.PriorityQueueIt is not a new style class, but super only works with new style classes . You have to use

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

instead.

+7
source

All Articles