View Function Signatures
00:34 As you provide values for your function, bpython highlights the current parameter name in the function signature to indicate how many are left. This can be really helpful when the function expects multiple arguments.
Function signatures already provide plenty of useful information that can help you understand what a function or method does without having to look up its documentation. However, bpython goes the extra mile by displaying a docstring from the function’s body if it can find and extract one from the source code. In this example, both the
sub() function and Python built-in
max() function have docstrings that bpython shows.
Sometimes it may include details about the function arguments or automated doctests to self-test and demonstrate how to use the function. Automatically displaying docstrings is more efficient than using Python’s built-in
help() function or accessing the function’s
01:48 If neither the function signature nor the docstring is enough for you, then you can use bpython to reveal the underlying source code. Many contemporary code editors let you navigate to the definition of a symbol by clicking on it or holding a designated key.
This works equally well for symbols that you defined in your project and ones that are defined in the Python standard Library or a third-party package installed with
pip. In bpython, you can display a read-only preview of the corresponding source code by pressing F2. After typing a given symbol,
The source code preview opens in your operating system’s default terminal pager program, which is usually the Unix
less command. You can use the arrow keys or Page Up and Page Down to scroll up and down.
02:55 press Q to quit. Whether you use a code editor or bpython, this feature will only work as long as there’s pure Python source code available. If the symbol that you’re interested in is a built-in function, or is implemented as an extension module in the C programming language, then you won’t be able to get any information about it. Instead, bpython will display a message that no source code was found.
Become a Member to join the conversation.