1

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.

1 Answer 1

1

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.)

Sign up to request clarification or add additional context in comments.

1 Comment

That works, thanks. It does seem rather a pain to have to change one's code just to get readable help text. I looked in the pydoc module and found how it was getting information for functions, and I can't see a simple way around it (other than altering my code). By the way the project is Python 3 only. Thanks for the advice, but I'm not concerned about backward compatibility. This is only a small part of the code, there's no way the rest will ever work on Py2 anyway.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.