Configure bpython Settings
00:12 bpython relies on defaults that are initially hard-coded in its source code. It’s only when you request to edit the configuration by pressing F3 in bpython that it will create the file from scratch and open it for you in a code editor.
00:34 This file resembles a Windows INI file with key-value pairs grouped by categories. These are processed by bpython using the configparser module. After saving the updated configuration, you’ll need to restart bpython for the changes to take effect.
01:02 It’s often easier to edit the configuration file in a different editor, so you’ll need to know the location of the configuration file to do this. The default location of the config file is a hidden subdirectory of the user’s home folder, which can be accessed at the location seen on-screen, on macOS and Linux and also under WSL on Windows.
01:34 This can be useful if you want to have different configurations for different projects. The command to edit the file in nano or pico, which is available on macOS, Linux, and WSL, is seen on-screen.
01:52 It’s good to know the default location of the configuration file in case it has an error preventing bpython from starting. When it does, you can open the file in a text editor and fix the problem by hand.
02:05 While there are many options available to you, in the next few sections, you’ll go through the most important bpython settings. One of the first things you might want to change to improve your bpython experience is the external code editor, which defaults to the text-based vi.
03:11 Because bpython expects the configuration values to be valid Python literals, make sure that you type an integer literal for this option. You can use the underscore character to visually separate groups of digits.
For other configurable options available in bpython, including those that bpython may not generate when you first edit the configuration file, check out the configuration page in the official documentation at the link seen on-screen. The next section that you’ll find in bpython’s configuration file is tagged as
03:46 It represents keyboard shortcuts bound to specific actions such as clearing the screen or showing the source code preview. You can define custom key bindings using the syntax seen on-screen, but how do you know the names of the options that correspond to the available actions in bpython? Fortunately, the generated configuration file contains commented-out mappings of actions and their default keyboard shortcuts. You can uncomment and update them.
04:42 Many code editors allow you to change the color theme. This can help reduce eyestrain by letting you switch between light and dark themes to adapt to the lighting conditions in your environment. Also, if you get bored with a default color theme or require greater contrast, you can always choose a theme that better suits your needs.
Note that you don’t include the
.theme suffix here because bpython always appends it to the specified file stem. Now you can edit your custom theme file, which in this case on-screen has contents inspired by the sample light theme available on bpython’s GitHub repository.
Unfortunately, there’s only a small set of fixed color markers that you can choose from, and they’re seen on-screen. On the upside, you can make the font bold by using uppercase letters, so there’s a tiny bit of room for variety and creativity. For example, the uppercase letter
Y will make your text yellow and bold.
Become a Member to join the conversation.