# Reloading the REPL in Python

DevFeed: [Reloading the REPL in Python](<https://devfeed.tech/articles/reloading-the-repl-in-python-28231.md>)

Original publisher: [Read original article](<http://fuzzyblog.io/blog/python/2020/03/07/reloading-the-repl-in-python.html>)

Author: Fuzzygroup

Published: 2020-03-07T00:00:00Z

Content type: tutorial

Language: en

Sources: [Scott Johnson](<https://devfeed.tech/sources/scott-johnson.md>)

Topics: [Python](<https://devfeed.tech/topics/python.md>), [Rails](<https://devfeed.tech/topics/rails.md>), [Code](<https://devfeed.tech/topics/code.md>), [import](<https://devfeed.tech/topics/import.md>), [IPython](<https://devfeed.tech/topics/ipython.md>)

Tags: [code](<https://devfeed.tech/tags/code.md>), [import](<https://devfeed.tech/tags/import.md>), [python](<https://devfeed.tech/tags/python.md>), [rails](<https://devfeed.tech/tags/rails.md>)

## AI overview

A tutorial on reloading changed Python modules in an interactive REPL using importlib.reload(), with a comparison to Rails' reload! command and an example of automating the process through an IPython configuration.

## Source excerpt

When you know something well you always look to learn by analogy. Today's short topic is reloading the REPL (read-evaluate-print-loop) interactive console in Python and then contrast between Python and Rails. And, yes, I get that Python is a language and Rails is a framework but where you tend to work directly in the Python console, you also tend to work directly in the Rails console (as opposed to the IRB Ruby console on which the Rails console is based but the Rails console improves it a lot). The reason this is important is that if you use a REPL a lot, well, you are constantly switching between editor and REPL and until this damn blog post, I had to quit my Python console every damn time. Just imagine me cursing up a blue streak and you will get a small fraction of my frustration when you see the difference below between Python and Rails. Python - Launching the Console python3 Rails - Launching the Console rails c Note: You may have to type this as bundle exec rails c (also knowing as the "bundle exec" tax). Python - Reloading the Console When You Change Your Code import importlib importlib.reload(your_module_name_here) Example: import expert_classification # try some code; find bug; fix bug import importlib importlib.reload(expert_classification) # try code again Rails - Reloading the Console When You Change Your Code reload! Note: If you change your Rails gem stack then you have to exit the console entirely. I'll give you that. Why This Matters, Why Rails is Better Here And a Rant It is hard to know when you're changing stuff with more than a single module exactly what you changed. The Rails method of typing reload! and having your whole environment reloaded solved this entirely. Note: The reload method on importlib is new in Python 3.4. Insert emoji of Munsch scream here How the hell is this possible that reloading came only on March 17, 2014 when Python started shipping in December 1989? I can't remember ever not having reload! in Rails. Sidebar: Making this