python - pydoc 生成带有文件句柄参数的帮助文本

标签 python pydoc

我有一个带有以下参数列表的函数:

def print(*line, sep=' ', end='\n', file=sys.stdout, default = 'full'):

不幸的是,该模块的 pydoc 帮助文本显示如下:

FUNCTIONS
print(*line, sep=' ', end='\n', file=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='cp850'>, default='full')

如何让 pydoc 将文件参数指定为 file=sys.stdout 而不是显示对象的详细细节?

顺便说一下,Python 3.2。

最佳答案

简单的解决方案:

def print(*line, sep=' ', end='\n', file=None, default = 'full'):
    '''If file is None, defaults to sys.stdout.'''

    if file is None:
        file = sys.stdout

(但请考虑不要使用 printfile 作为标识符。print 特别是会永远破坏 Python 2 兼容性。)

关于python - pydoc 生成带有文件句柄参数的帮助文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7415386/

相关文章:

python - 百分比计算不起作用

python - Pyramid:多线程数据库操作

Python GTK 3+ : How to center text within Combobox widget?

Python:如何转换日期时间格式?

python - 如何让 pydoc 命令在 Windows 7 cmd 中工作?

python - Pydoc 网络服务器在 ubuntu 上不起作用

python - 发现未记录程序的 IPC 接口(interface)?

python - 如何理解文档中的pydoc参数

python - 如何使用 Pydoc 创建文档?