Fix Mistakes Quickly
00:00 Fix Mistakes More Quickly. Code editing capability is another area where the Python standard REPL is lacking. Often you’ll find yourself retyping the same piece of code over and over because typos in nested blocks are difficult to fix without starting from scratch.
00:28 The bpython REPL makes editing and reevaluating your code a breeze, offering many useful features that allow you to rewind one or more lines, edit code in an external editor, or reload imported modules.
00:43 Here you’ll learn how to use these neat features of bpython to quickly fix mistakes and typos or to change the implementation of your code. When you make a typo in the middle of a code block using the standard Python REPL, then you have to retype the entire block of code from scratch.
01:54 But even with this limitation, the rewind feature is a great way to fix a mistake that you spotted right after making it, but it’s ill-suited for fixing earlier errors or for making major changes.
02:05 For this, bpython has something else to offer. By pressing Ctrl and X on your keyboard, you can add or modify code located in the current line in your bpython REPL using an external code editor.
02:34 The default editor configured in bpython is vi, which is an historically accurate choice, but one which leads to a lot of head scratching. There’s an old joke about being able to generate random keypresses by seeing how people try to get out of vi, and this is for good reason.
you finish typing, press Escape, and you’ll go back to command mode. The magic key combination that you need to send your code back to bpython is
:wq as seen on screen. Once you hit Enter, the code will be sent back to bpython and evaluated.
03:40 While vi is a powerful editor, it’s not friendly, so you may want to choose a different editor that doesn’t require as much learning to master. You’ll find out how to change the code editor in bpython to something more modern, such as Visual Studio Code, later on in the course.
04:14 This time you see the entire contents of the REPL session, including any outputs of the previous instructions in the form of comments. They’ll be ignored, as bpython will eventually reevaluate your session when you close the editor.
Become a Member to join the conversation.