import sys
import pydoc
def output_help_to_file(filepath, request):
f = open(filepath, 'w')
sys.stdout = f
pydoc.help(request)
f.close()
sys.stdout = sys.__stdout__
return
import sys
output_help_to_file('abc.log', sys)
来源:https://stackoverflow.com/questions/11265603/how-do-i-export-the-output-of-pythons-built-in-help-function