Python – Reload a Module in Python 3.4

pythonpython-3.4python-3.xpython-module

I know this might sound like a really stupid question but whatever. I've made a small script in Python and I've made some changes while in a shell. Normally, on an OS X computer (It's running Python 2.7), I would simply type in reload(the_module) and it would reload my module that includes the changes that I have made. However, when I am reloading the module here (on windows python v. 3.4), it simply gives me this:

>>> reload(instfile)
Traceback (most recent call last):
  File "<pyshell#5>", line 1, in <module>
    reload(instfile)
NameError: name 'reload' is not defined

And then when I type in imp.reload(my_module), it simply says that the function is deprecated. I can't seem to find what the new function (or it's equivalent) would be anywhere so if someone can help me that would be great! 🙂

Best Answer

The imp module was deprecated in Python 3.4 in favor of the importlib module. From the documentation for the imp module:

Deprecated since version 3.4: The imp package is pending deprecation in favor of importlib.

So, you should be using the reload function from there:

>>> import importlib
>>> importlib.reload
<function reload at 0x01BA4030>
>>> importlib.reload(the_module)