BMW CarIT Logo Typo

Blog

News, ideas and events

Blog

The built-in Python help system

Background

Sometimes you may find yourself in a situation without internet connectivity, like in a plane, but still you want/need to browse the Python documentation.
So what can you do if you can not reach the online documentation [1] ?

The Python built-in help system

The answer to the aforementioned question is easy: you start up the Python interpreter (on the command line, in interactive mode).
The Python interpreter tells you right after its version number what to do: Type help for more information.

Starting Python on the console
C:\programs\_dev\_python\python_3_5_2>python.exe
Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:01:18) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>

Doing so reveals that there are two kinds of built-in help systems, the interactive help and the Python object documentation browser.

There are two kinds of help builtins
>>>
>>> help
Type help() for interactive help, or help(object) for help about object.
>>>

The interactive help system

This help system is pretty self explanatory. It can list you all available modules, keywords, symbols or topics.
For each entry in those listings you then can query further help.

The Python interactive help system
>>> help()

Welcome to Python 3.5's help utility!

If this is your first time using Python, you should definitely check out
the tutorial on the Internet at http://docs.python.org/3.5/tutorial/.

Enter the name of any module, keyword, or topic to get help on writing
Python programs and using Python modules.  To quit this help utility and
return to the interpreter, just type "quit".

To get a list of available modules, keywords, symbols, or topics, type
"modules", "keywords", "symbols", or "topics".  Each module also comes
with a one-line summary of what it does; to list the modules whose name
or summary contain a given string such as "spam", type "modules spam".

help>

The help system has a pagination support. Whenever the content is longer then your current console size, you can scroll pagewise with the SPACE bar or linewise with the RETURN key.
To exit the interactive help system just press RETURN .

The Python object documentation browser

If you already know which module/object documentation you need, you can use the object documentation browser.
Be aware that you have to import the module to use the documentation browser.

Object documentation browser
>>> help(glob)
Traceback (most recent call last):
  File ">stdin>", line 1, in <module>
NameError: name 'glob' is not defined
>>> import glob
>>> help(glob)
Help on module glob:

NAME
    glob - Filename globbing utility.

FUNCTIONS
    escape(pathname)
        Escape all special characters.

... omitted for brevity ...

DATA
    __all__ = ['glob', 'iglob', 'escape']

FILE
    c:\programs\_dev\_python\python_3_5_2\lib\glob.py


>>>

Conclusion

The Python interpreter has a built-in documentation browser, that works even with external/3rd party modules (if they are well documented).

Links

[1] https://docs.python.org/3/