[Python-ideas] Adding an 'errors' argument to print

Victor Stinner victor.stinner at gmail.com
Fri Mar 24 12:37:33 EDT 2017


*If* we change something, I would prefer to modify sys.stdout. The
following issue proposes to add
sys.stdout.set_encoding(errors='replace'):
http://bugs.python.org/issue15216

You can already set the PYTHONIOENCODING environment variable to
":replace" to use "replace" on sys.stdout (and sys.stderr).

Victor

2017-03-24 16:41 GMT+01:00 Ryan Gonzalez <rymg19 at gmail.com>:
> Recently, I was working on a Windows GUI application that ends up running
> ffmpeg, and I wanted to see the command that was being run. However, the
> file name had a Unicode character in it (it's a Sawano song), and when I
> tried to print it to the console, it crashed during the encode/decode. (The
> encoding used in cmd doesn't support Unicode characters.)
>
> The workaround was to do:
>
>
> print(mystring.encode(sys.stdout.encoding,
> errors='replace).decode(sys.stdout.encoding))
>
>
> Not fun, especially since this was *just* a debug print.
>
> The proposal: why not add an 'errors' argument to print? That way, I
> could've just done:
>
>
> print(mystring, errors='replace')
>
>
> without having to worry about it crashing.
>
> --
> Ryan (ライアン)
> Yoko Shimomura > ryo (supercell/EGOIST) > Hiroyuki Sawano >> everyone else
> http://refi64.com
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>


More information about the Python-ideas mailing list