Search Queue

abcd codecraig at gmail.com
Tue Jan 16 16:22:30 CET 2007


I have a class such as...

id = 0
class Foo:
    def __init__(self, data):
        self.id = id
        id += 1
        self.data = data

And I am storing them in a Queue.Queue...

import Queue
q = Queue.Queue()
q.put(Foo('blah'))
q.put(Foo('hello world'))
q.put(Foo('test'))

how can I search "q" for an instance of Foo which has 'id' equal to say
2?  Typically a queue only lets you put and get, not really search.

Thanks.




More information about the Python-list mailing list