Using Queue in python

前端 未结 5 1742
无人及你
无人及你 2021-02-06 23:31

I\'m trying to run the following in Eclipse (using PyDev) and I keep getting error :

q = queue.Queue(maxsize=0) NameError: global name \'queue\' is not defined<

5条回答
  •  自闭症患者
    2021-02-07 00:12

    You do

    from queue import *
    

    This imports all the classes from the queue module already. Change that line to

    q = Queue(maxsize=0)
    

    CAREFUL: "Wildcard imports (from import *) should be avoided, as they make it unclear which names are present in the namespace, confusing both readers and many automated tools". (Python PEP-8)

    As an alternative, one could use:

    from queue import Queue
    
    q = Queue(maxsize=0)
    

提交回复
热议问题