Help us understand the problem. What is going on with this article?

.pyファイルの再import

More than 5 years have passed since last update.

概要

IPython Notebook等でmoduleの読み込みだけしてコード自体は別のテキストエディタで編集しているときに2回目以降のimportが効かなかったのでメモ。

解決策

sys.modulesから読み込みたいモジュールを消す。

fuga.py
import sys
try:
    del sys.modules['hoge']
except Exception as e:
    pass
import hoge
nel215
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away