0

I'm using the Atom text editor to write my code in, and then importing into the Python 3.4 command line interpreter. If I make a mistake in the code and have to make a fix, I'm unable to see the changes reflected in the interpreter until I close and re-open it. This happens even if I re-import the file. Does it have a cache that I need to clear? How does one see code changes in the interpreter without closing it?

flybonzai
  • 3,763
  • 11
  • 38
  • 72
  • `import importlib; importlib.reload(your_module)` – zero323 Jul 16 '15 at 23:58
  • When you type a question, a list of potentially related questions appears. Please go through that **entire list** to make sure your question isn't a duplicate before posting a new question. – MattDMo Jul 17 '15 at 00:01

1 Answers1

1

When you load a python module in the interpreter, it reads all the imported code once, then caches that code for later use. This means that if you make any changes to the module, you'll have to tell the interpreter to reload its content. This is pretty easy to do:

>> import foo  # crystallizes foo code in your interpreter to the state it was in at time of import

>> # [updates made to foo code]

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

That should be it!

[note: importlib is new in python 3.4 . Before that, imp had the same functionality. In python 2 the reload() function is just part of the default namespace.]

Walker
  • 423
  • 3
  • 8