Groups
Groups
Sign in
Groups
Groups
comp.lang.python
Conversations
About
Send feedback
Help
Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss
Learn more
import queue in Python 2 and Python 3
249 views
Skip to first unread message
Benjamin Chaney
unread,
Jun 30, 2017, 12:33:19 AM
6/30/17
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to
What is the best way to import the synchronized queue class that is
compatible with both Python2 and Python3. Right now I am using the
following:
>if sys.version_info < (3, 0):
> import Queue as queue
>else:
> import queue
This seems somewhat unpythonic. Is there a better way without
installing extra packages?
Thanks,
Ben
Chris Angelico
unread,
Jun 30, 2017, 12:38:19 AM
6/30/17
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to
try:
import queue
except ImportError:
# Python 2
import Queue as queue
ChrisA
Thomas Jollans
unread,
Jun 30, 2017, 4:35:12 AM
6/30/17
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to
What Chris said. If you find yourself doing a lot of this kind of thing,
you might want to use six, though, and do
from six.moves import queue
0 new messages