LoginSignup
33
24

More than 5 years have passed since last update.

【備忘録】Python3でのreload

Last updated at Posted at 2015-12-07

Python3で読み込んだモジュール(loadしたモジュール)を再読み込みするためには、imoortlibモジュールのreloadを使います。

例えば、

>>> import importlib
>>> importlib.reload(foo)

とすると、foo.pyが再度読み込まれます。

再ロードされた際には、グローバル変数などは はそのまま残ります。
関数などの再定義を行うと、すでに定義されているものを上書きします。

以前に使われていたimpモジュールはPython3.4からは非推奨のようです。
「The imp package is pending deprecation in favor of importlib.」だそうです。

33
24
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
33
24