LoginSignup
1
2

More than 5 years have passed since last update.

Python2とPython3両方でQueueをimportする方法

Last updated at Posted at 2018-04-21

背景

モジュール名が変わっている
Python3でQueueを使う場合

import queue

Python2でQueueを使う場合

import Queue

解決法

try:
    import queue
except ImportError:
    import Queue as queue

q = queue.Queue()

この方法だとPython2でもPython3でも同じように利用できる。

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2