我有一个带有以下参数列表的函数:
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
(但请考虑不要使用 print
和 file
作为标识符。print
特别是会永远破坏 Python 2 兼容性。)
关于python - pydoc 生成带有文件句柄参数的帮助文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7415386/