Python Programming/Self Help
This book is useful for learning Python, but there might be a topic that the book does not cover. You might want to search for modules in the standard library, or inspect an unknown object's functions, or perhaps you know there is a function that you have to call inside an object but you don't know its name. This is where the interactive help comes into play.
Built-in help overview
[edit | edit source]Built-in interactive help at a glance:
help()# Starts an interactive helphelp("topics")# Outputs the list of help topicshelp("OPERATORS")# Shows help on the topic of operatorshelp("len")# Shows help on len functionhelp("re")# Shows help on re modulehelp("re.sub")# Shows help on sub function from re modulehelp(len)# Shows help on the object passed, the len functionhelp([].pop)# Shows help on the pop function of a listdir([])# Outputs a list of attributes of a list, which includes functionsimportrehelp(re)# Shows help on the help modulehelp(re.sub)# Shows help on the sub function of re modulehelp(1)# Shows help on int typehelp([])# Shows help on list typehelp(def)# Fails: def is a keyword that does not refer to an objecthelp("def")# Shows help on function definitions
Navigating Help
[edit | edit source]To start Python's interactive help, type "help()" at the prompt.
>>>help()
You will be presented with a greeting and a quick introduction to the help system. For Python 2.6, the prompt will look something like this:
Welcome to Python 2.6! This is the online 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/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, or topics, type "modules", "keywords", or "topics". Each module also comes with a one-line summary of what it does; to list the modules whose summaries contain a given word such as "spam", type "modules spam".
Notice also that the prompt will change from ">>>" (three right angle brackets) to "help>" You can access the different portions of help simply by typing in modules, keywords, or topics.
Typing in the name of one of these will print the help page associated with the item in question. To get a list of available modules, keywords, or topics, type "modules","keywords", or "topics". Each module also comes with a one-line summary of what it does; to list the modules whose summaries contain a given word such as "spam", type "modules spam".
You can exit the help system by typing "quit" or by entering a blank line to return to the interpreter.
Help Parameter
[edit | edit source]You can obtain information on a specific command without entering interactive help.
For example, you can obtain help on a given topic simply by adding a string in quotes, such as help("object"). You may also obtain help on a given object as well, by passing it as a parameter to the help function.
External links
[edit | edit source]- help in 2. Built-in Functions, docs.python.org