Re: Problem Regarding Queue

2010-02-09 Thread Rob Williscroft
mukesh tiwari wrote in news:80fed7d5-76eb-40c8-ace1-0c35736de399
@t17g2000prg.googlegroups.com in comp.lang.python:

> Could some one please tell what is wrong with this code. I am trying
> to use Queue in this program but i am getting error

The type you appear to be trying to use is Queue.Queue which you import
with:

from Queue import Queue 

http://docs.python.org/library/queue.html?highlight=queue#Queue.Queue

> Q_1=Queue()
> Q_2=Queue()
> Q_1.put(n)
> while(not Q_1.empty()):
> l=Q_1.get()
> if(rabin_miller(l)):
> Q_2.put(l)
> continue
> d=pollard(l)
> if(d==l):Q_1.put(l)
> else:

As the help page above points out also check out the deque Class:

http://docs.python.org/library/collections.html#collections.deque

Rob.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem Regarding Queue

2010-02-09 Thread Stephen Hansen
On Tue, Feb 9, 2010 at 2:06 PM, mukesh tiwari
wrote:

> Could some one please tell what is wrong with this code. I am trying
> to use Queue in this program but i am getting error
> Traceback (most recent call last):
>  File "/home/user/NetBeansProjects/NewPythonProject2/src/
> Pollard_rho.py", line 80, in 
>factor(n)
>  File "/home/user/NetBeansProjects/NewPythonProject2/src/
> Pollard_rho.py", line 59, in factor
>Q_1=Queue()
> NameError: global name 'Queue' is not defined.
>

That's because you haven't imported the Queue module.

You need to do:

import Queue

Then call:

Q_1 = Queue.Queue()

Alternately, you can do:

from Queue import Queue

And instantiate the class the same way you previously were.

--S
-- 
http://mail.python.org/mailman/listinfo/python-list