0

Been trying to read documentation and looking at online examples but my queue still returning None.

    from collections import defaultdict
    from Queue import Queue 

    -- in my init

    self.tickerPrices = dict()
    queue = Queue(maxsize=5)
    queue.put((0.00097073, 67689.70942763))
    self.tickerPrices['a'] = queue

    def appendToTickerDict(self, tickerid, askprice, volume):
      if(tickerid in self.tickerPrices):
            tickerQueue = self.tickerPrices[tickerid].put((askprice, volume))  --RETURNS NONE

tickerQueue returns None. Before this step, I tested it and saw that if I add something to this queue in the init, it shows up with .get before executing this code

Any tips would be most helpful.

Java investor
  • 117
  • 3
  • 12
  • 1
    `put()` is not meant to return anything but because every Python function has to return something it returns `None` – Michael Butscher Dec 18 '17 at 02:29
  • See the [documentation for `Queue.put`](https://docs.python.org/3/library/queue.html#queue.Queue.put). It does not return anything. – Galen Dec 18 '17 at 02:35
  • Right. The [documentation for `Queue.get`](https://docs.python.org/3/library/queue.html#queue.Queue.get) states that it removes and returns an item from the queue. – Galen Dec 18 '17 at 02:37
  • @Galen is there a way to iterate over the Queue without actually removing the element? – Java investor Dec 18 '17 at 02:41
  • That is typically not the use of Queue. It sounds like you want something like a list. However, if you need the Queue for something else, see [How to iterate Queue.Queue items in Python](https://stackoverflow.com/questions/8196254/how-to-iterate-queue-queue-items-in-python). – Galen Dec 18 '17 at 02:48
  • @Galen that did the trick. Thanks! – Java investor Dec 18 '17 at 03:29

1 Answers1

0

you can see python language references expression-statements.

py9527
  • 16
  • 2