How do you use `help` when write your code

Steven D'Aprano steve+comp.lang.python at
Sun Jul 6 19:52:50 CEST 2014

On Mon, 07 Jul 2014 00:36:23 +0800, Shiyao Ma wrote:

> Hi Pythonistas
> I often heard people mention use help(ob) as a way of documentation look
> up. Personally I seldom/never do that. My normal workflow is use
> ipython, obj? or obj?? for quick look up or use for a
> detailed read.
> Do you use `help`? How does it integrate into your workflow?

I frequently use the help() function. 

(By the way, a little trivia for you: although the help function is in 
the built-in namespace, it is not actually a built-in! When you start 
Python interactively, the script runs automatically, creates the 
help() function, and monkey-patches it into the builtins namespace.)

I rarely use ipython, I use the regular Python interactive interpreter, 
so obj? and obj?? aren't an option.

My usual workflow is to have at least one Python interpreter open at all 
times. If I don't remember the parameters for a method or function, I'll 
call help(class.method) or help(function). If I'm not sure what the 
method is called, I'll usually call help(class) or help(module). If there 
are too many things in the class or module, I'll use dir() to inspect it 
first. I have a monkey-patched version of dir() which takes a second 
argument, a glob, to filter the list of names returned:

py> len(dir(os))  # Too much!
py> dir(os, 'env')
['_putenv', '_unsetenv', 'environ', 'environb', 'getenv', 'getenvb', 
'putenv', 'supports_bytes_environ', 'unsetenv']
py> dir(os, 'env*')
['environ', 'environb']


More information about the Python-list mailing list