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.
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
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.
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.
Become a Member to join the conversation.