您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

如何导出Python内置的help()函数的输出

如何导出Python内置的help()函数的输出

这有点骇人听闻(并且某处可能有更好的解决方案),但这可行:

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

接着…

>>> output_help_to_file(r'test.txt', 're')
python 2022/1/1 18:25:33 有466人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶