import queue in Python 2 and Python 3
Chris Angelico
rosuav at gmail.com
Fri Jun 30 00:37:59 EDT 2017
On Fri, Jun 30, 2017 at 2:06 PM, Benjamin Chaney
<chaneybenjamini at gmail.com> wrote:
> 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?
>
try:
import queue
except ImportError:
# Python 2
import Queue as queue
ChrisA
More information about the Python-list
mailing list