Re: bisect and Queue modules in Python 2.4
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.python archive

Re: bisect and Queue modules in Python 2.4

From: Peter Otten <__peter__@web.de>
Date: Thu Mar 16 2006 - 15:45:50 CET

SA Trygubenko wrote:

> q.queue used to be a list, and now it is something else?
>
> I was using bisect module to implement min priority queue, as described
> in python library reference (see
> http://www.python.org/doc/2.3.5/lib/bisect-example.html). I have found
> out that in Python 2.4 q.queue does not support "insert" anymore, which
> breaks bisect. Please help!

class PriorityQueue(Queue.Queue):
    def _put(self, item):
        bisect.insort(self.queue, item)
    def _init(self, maxsize):
        self.maxsize = maxsize
        self.queue = []
    def _get(self):
        return self.queue.pop(0)

or somesuch might work.

Peter
Received on Sun Apr 30 12:00:19 2006