On 27 March 2017 at 13:10, Steve Dower <steve.do...@python.org> wrote:
> On 26Mar2017 0707, Nick Coghlan wrote:
>>
>> Perhaps it would be worth noting in the table of error handlers at
>> https://docs.python.org/3/library/codecs.html#error-handlers that
>> backslashreplace is used by the `ascii()` builtin and the associated
>> format specifiers
>
> backslashreplace is also the default errors for stderr, which is arguably
> the right target for debugging output. Perhaps what we really want is a
> shorter way to send output to stderr? Though I guess it's an easy to invent
> one-liner, once you know about the difference:
>
>>>> printe = partial(print, file=sys.stderr)

If there was a printerror builtin that used sys.stderr as its default
output stream, it could also special case BaseException instances to
show their traceback.

At the moment, we do force people to learn a few additional concepts
in order to do error display "right":

- processes have two standard output streams, stdout and stderr
- Python makes those available in the sys module
- the print() builtin function lets you specify a stream with "file"
- so errors should be printed with "print(arg, file=sys.stderr)"
- to get exception tracebacks like those at the interactive prompt,
look at the traceback module

As opposed to "for normal output, use 'print', for error output, use
'printerror', for temporary debugging output also use 'printerror',
otherwise use the logging module".

Cheers,
Nick.

-- 
Nick Coghlan   |   ncogh...@gmail.com   |   Brisbane, Australia
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to