Search code examples
pythonpydoc

pydoc generated help-text with file handle parameters


I have a function with the following parameter list:

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

Unfortunately the pydoc help text for the module shows it like this:

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

How can I make pydoc give the file argument as file=sys.stdout rather than showing the gory details of the object?

Python 3.2, by the way.


Solution

  • Easy solution:

    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
    

    (But please consider not using print and file as identifiers. print esp. will break Python 2-compatibility forever.)