Getting Help and Introspecting Code in the Standard REPL
00:00 Getting Help and Introspecting Code in the REPL. An important feature of any coding environment such as an IDE, editor, or REPL is the possibility of getting quick help and guidance about using the language, libraries, and tools that you are working with.
help() function gives you access to Python’s built-in help system. You can use this function by calling it in two ways: with an object or string as an argument, which gives you access to the object’s help page, or with no arguments, which enters Python’s help system.
The help page of an object typically contains information from the object’s docstrings. It may also include a list of methods and attributes. For example, here’s a fragment from the page of the
str class that you can access as seen on-screen. In this example, you use the
str class object as an argument to
You can use the up and down keys to move through the page. When you get to the desired information, you can press Q to exit the help viewer. If you use a string as an argument to
help(), then the help system looks for it as the name of a module, function, class, method, keyword, or documentation topic.
This way to call
help() comes in handy when the target object isn’t available in your current namespace. For example, let’s say you want to get help on the
pathlib module, but you haven’t imported it yet.
In help mode, you can enter keywords, module names, function names, or any other name. The help system will search for the target name and present the associated documentation page. To try this out, type
sys on the
help> prompt and then press Enter.
03:44 This way, you’ll be back to your REPL session. When you’re working in a REPL session, you have direct access to some Python built-in tools that you can use to introspect your code and obtain more information and context on the objects that you are working with. Some of these tools are seen on-screen.
04:03 You can use any of these built-in functions to introspect your code and retrieve useful information that you can later use in your coding process. For example, let’s say you are working with dictionaries and want to get a list of all the methods and attributes in the class.
Become a Member to join the conversation.