我有一个python包,它输出了相当多的帮助文本:help(package)
我想以help(package)
显示的格式将此帮助文本导出到文件中
我该怎么做呢?
发布于 2018-08-17 16:47:13
这是一个老问题,但较新的recommended通用解决方案(针对Python 3.4+)用于编写print()
到终端使用contextlib.redirect_stdout
的函数的输出
import contextlib
def write_help(func, out_file):
with open(out_file, 'w') as f:
with contextlib.redirect_stdout(f):
help(func)
使用示例:
write_help(int, 'test.txt')
https://stackoverflow.com/questions/11265603
复制相似问题