[Python-ideas] Help mode improvement.

Steven D'Aprano steve at pearwood.info
Tue Oct 11 03:39:31 CEST 2011


Stayvoid wrote:
> Hi there!
> 
> I want to make an improvement connected with the interactive help mode.
> 
> Example:
> You want to check some keys in the dictionary, but you can't remember
> the syntax of the command.
>
> If you type something like this: help(key), the interpreter will
> output an error. Because help(key) is just a plain
> expression, and it tries to evaluate key first before even calling
> help(). Maybe help(*key*) could make it work?

Remember that the help() function is just a regular function, like any 
other. It isn't magic, and it can't accept anything that isn't a valid 
Python object. That won't change.

help(math) won't work unless you have imported the math module first.

help(key) won't work unless you actually have a name `key`, in which 
case it will work but it may not do what you are expecting.

help(*key*) can't work because *key* is a SyntaxError.


However, help('key') would work. It currently says:

 >>> help('key')
no Python documentation found for 'key'

 >>>

Perhaps help should be more aggressive at trying to find something 
useful before giving up. Or you could just encourage the beginner to use 
help interactively, by calling help() with no arguments, then following 
the prompts.



> In my opinion it will be very helpful for newcomers if the interpreter
> could search for similar commands and output them all.

A keyword search facility, familiar to Linux users as `man -k key` or 
`apropos key`, might be useful. Or it might also complicate the 
interactive help for no good reason. Beware of trying to make help() do 
too much.

Remember also that help() is not a substitute for the Python 
documentation and tutorials. It is not aimed at teaching beginners the 
basics. You actually need a reasonably good grasp of Python skills to 
get the most from the interactive help.



-- 
Steven




More information about the Python-ideas mailing list