Auto-Indentation and Contextual History
00:00 Auto-Indentation and Contextual History. When you write long blocks of code in the Python standard REPL, you must correctly indent each line yourself. This can be tedious, error-prone, and unnatural if you’re used to writing code in a full-fledged editor.
00:31 The default indentation in bpython is four spaces, which complies with the Python style described in a document called PEP 8. However, you can change the corresponding tab length option in bpython’s configuration if you prefer a different indentation size.
The standard Python REPL keeps an unlimited history of the inline instructions that you type previously, even those from finished interpreter sessions. You can find your command history in a file named
.python_history located in your user’s home directory. On the other hand, your bpython history is stored separately in a file called
.pythonhist and is limited to a hundred lines by default, although you can increase that limit in the configuration.
01:35 Despite these differences, both the standard Python REPL and bpython conceptually support the same basic commands to access the history. bpython also maintains a contextual history with results.
01:48 Depending on where you are in your code, you can browse the history by using the arrow keys on your keyboard. The up arrow goes back in time, and the down arrow goes forward in time one line of code at a time.
02:26 Notice how the historical suggestions offered by bpython don’t always follow their chronological order. Instead, bpython filters out suggestions that wouldn’t fit the context on your current indentation level.
02:41 Unlike the standard Python REPL, in bpython, history also comes into play when you start typing a line of code that’s already been executed before. As soon as bpython finds a historical entry that begins with a matching character sequence, it will show a grayed-out completion.
Become a Member to join the conversation.