views:

73

answers:

1

Hi,

I have the following 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?

+7  A: 

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.

unutbu
Perfect. Thanks a lot!
Yassin
actually, you will also need to pass 'self' explicitly: Queue.PriorityQueue.put(self, (item.priority, item))
Ivo van der Wijk
@Ivo: Yes; thanks for the correction!
unutbu