Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Reload Imported Modules

00:00 Reloading Imported Modules. You can use any code editor in conjunction with bpython to modify helper functions and classes defined in your local modules or packages and have them reloaded in the current REPL session on demand.

00:16 It’s a great way to test and debug code without restarting bpython when you change some imported code.

00:49 After saving your updated modules in a code editor, press F6 in bpython to reload them and reevaluate the complete session since starting the REPL. Reloading modules keeps existing instructions in the current REPL session intact and reruns them, resulting in updated outputs.

01:08 This feature is an invaluable tool for exploratory testing. It can boost your productivity by cutting down on time spent restarting bpython and retyping the same instructions.

01:20 The bpython REPL also supports automatic module reloading so that you don’t have to manually hit a button every time you make a change to some code in an external editor. To take advantage of the auto-reload feature, you’ll have to install the external watchdog library as an optional dependency in the same virtual environment where you installed bpython.

01:50 Remember that whether you reload modules manually or let bpython do that automatically, it always triggers the complete session reevaluation. To enable the auto-reload feature, hit F5 while you’re in bpython.

02:08 It will start monitoring your imported modules and packages and automatically reload them in the current REPL session whenever you save one of your files.

02:18 Here you can see changes are being made to the greet() function and the real-time changes in bpython as these changes are made. This is a dramatic improvement over manual module reloading, and it can save you a lot of time.

02:34 To disable the auto-reload feature, hit F5 again, which works as a toggle.

02:42 As you can see, bpython provides several code editing features that are missing from the standard Python REPL, helping you fix mistakes and refactor your code more quickly.

02:53 But there’s more that you can do with bpython, whether you are a coder, a mentor, or a teacher. There are many situations where you’ll need to share your REPL session.

03:02 And bpython gives you several ways you can do this, which you’ll see in the next section of the course.

Become a Member to join the conversation.