2

My function calls aren't updating after I've edited them. I've assumed that I needed to reload() my module, however the reload function spits out an error. I'm testing my script on the console.

My PyCharm version is 2022.3.3 (Community Edition), and I'm running Python 3.7.

I've imported importlib.

from importlib import reload
reload(xxx)

xxx is my module name.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Chris H.
  • 21
  • 1
  • 1
  • 2
  • This is something seriously wrong with the search engines. How can this get about 1,500 views per day over its 65-day lifetime (currently in the top 10 in terms of view rate among all Stack Overflow question posted in the last about 2 years (several million questions)). – Peter Mortensen Aug 13 '23 at 23:46
  • Possibly related: *[Reloading module giving NameError: name 'reload' is not defined](https://stackoverflow.com/questions/961162/reloading-module-giving-nameerror-name-reload-is-not-defined)* – Peter Mortensen Aug 13 '23 at 23:52
  • Is this a duplicate? Or some unfortunate name clashing? – Peter Mortensen Aug 13 '23 at 23:56

1 Answers1

1

Yes, because you need to pass the module object itself, not just the module name as a string!

Check this out to fix the NameError issue:

import importlib
import xxx

importlib.reload(xxx)

To update and apply changes made to the xxx module, you can use importlib.reload(xxx). This function refreshes the module by importing it again. It's important to note that in Python 3.4 and later versions; the importlib module is already built-in and doesn't require additional installation.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Freeman
  • 9,464
  • 7
  • 35
  • 58