Wikipedia:Reference desk/Archives/Computing/2014 November 16

= November 16 =

a = help(list.append) and help(list.append)
Why are both method calls the same? Can't the 1st call save the help? I see that help returns None, but, what if I wanted to save the text of the help?--Senteni (talk) 17:02, 16 November 2014 (UTC)


 * Help prints the docstring, which is a property of the object called __doc__
 * So you'd do

a = list.append.__doc__
 * -- Finlay McWalterᚠTalk 20:22, 16 November 2014 (UTC)


 * More generally (and for more complicated problems where there isn't a simple string like this to look at) you can capture your programs own prints (to stdout) by temporarily substituting a StringIO object in for sys.stderr. This is overkill for your current problem, but might come in handy later. An example (which accomodates the changes to StringIO done between python2 and python3) is:


 * -- Finlay McWalterᚠTalk 21:06, 16 November 2014 (UTC)