[Python-ideas] Adding an 'errors' argument to print
Steven D'Aprano
steve at pearwood.info
Fri Mar 24 18:38:26 EDT 2017
On Fri, Mar 24, 2017 at 10:41:58AM -0500, Ryan Gonzalez wrote:
> 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.)
*Crash* crash, or just an exception? If it crashed the interpreter, you
ought to report that as a bug.
> The workaround was to do:
>
>
> print(mystring.encode(sys.stdout.encoding,
> errors='replace).decode(sys.stdout.encoding))
I think that this would be both simpler and more informative:
print(ascii(mystring))
--
Steve
More information about the Python-ideas
mailing list