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

Hint: You can adjust the default video playback speed in your account settings.
Hint: You can set your subtitle preferences in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please see our video player troubleshooting guide to resolve the issue.

Avoid Context Switching

00:00 Avoid Context Switching. While computers are made for multitasking, humans aren’t very good at it. Context switching requires your brain to save the current state of each task and then jump to a different task and continue from where you left off.

00:16 This takes time and energy and can lead to mistakes, reducing your productivity. As a programmer, you already have enough complexity to worry about, so your tools should work to minimize context switching. Integrated Development Environments (IDEs) address this problem by consolidating various tools for writing software into a single application.

00:38 The bpython REPL also provides features to help you maintain focus: type introspection, looking into objects at runtime to reveal their members; function signatures, seeing the expected parameters of functions and methods; docstrings, read the user-provided descriptions of types and functions; and source code, view the underlying code of an object at hand.

01:04 By having this information right where you need it, you no longer have to open another program to explore unfamiliar code, potentially losing track of what you are doing.

01:14 You’ll take a closer look at each of these features.

01:19 Code suggestions in bpython work in many places. One of them is Python’s operator for accessing members of an object. Normally, you need to know the names of attributes and methods defined in a class up front or check the corresponding documentation or source code to avoid an AttributeError. Fortunately, bpython allows you to introspect objects and filter their attributes at runtime without ever leaving the terminal. For example, let’s say you are creating a multi-threaded application and don’t remember the exact name of a given method or attribute in the threading.Thread class.

01:59 In this situation, you can use bpython as seen on-screen.

02:05 Note that only public members are displayed by default because under normal circumstances, you are not supposed to touch the object’s internal implementation. However, occasionally you may want to reach for or modify its internals. To reveal such private members in bpython, type one or two underscore characters right after the dot operator.

02:27 Many of the suggested members whose names start with a double underscore are in fact special methods that allow for operator overloading in Python.

02:41 You can also use bpython suggestions to explore Python modules and packages before importing them. The REPL knows what modules are importable in the existing session, including the Python standard library, third-party libraries installed with pip, and custom modules located in your project folder. To trigger those suggestions, type import, followed by a single space and at least one character, and then hit the Tab key.

03:16 Just as with inspecting object attributes, internal modules don’t show up as suggestions in bpython unless you explicitly request them by using the leading underscore or double underscore.

03:28 Once you import a specific module, you can examine its contents using the familiar dot operator as seen previously.

03:40 In the next section of the course, you’ll look at more ways that bpython can help you avoid context switching.

Become a Member to join the conversation.