[PYTHON] Reimport of .py file

Overview

Note that the second and subsequent imports did not work when the code itself was edited with another text editor just by reading the module with IPython Notebook etc.

solution

Delete the module you want to load from sys.modules.

fuga.py


import sys
try:
    del sys.modules['hoge']
except Exception as e:
    pass
import hoge

Recommended Posts

Reimport of .py file
Summary of python file operations
The story of the "hole" in the file
Efficient use of Linux file system
Summary of restrictions by file system
Use of constraints file added in pip 7.1
Handling of character code of file in IronPython
Check the existence of the file with python
[Python] Get the character code of the file
[Python3] Understand the basics of file operations