What is the best way to get the correct character output without ascii compatible with Python 2 and 3? This is true?
# -*- coding: utf-8 -*- from __future__ import unicode_literals from __future__ import print_function print("ȧƈƈḗƞŧḗḓ uʍop-ǝpısdn ŧḗẋŧ ƒǿř ŧḗşŧīƞɠ")
One of the problems with this approach is that it does not competently degrade in situations where output is limited (for example) to asciior latin1. The default behavior is to throw an exception, for example:
ascii
latin1
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-7: ordinal not in range(128)
... I would prefer to avoid error handling methods like 'replace' or 'backslashreplace' . Is there a way to configure sys.stdoutto use one of these methods? Is this a reasonable thing?
sys.stdout
Unicode encoding in Python has been discussed a lot in StackOverflow, for example: How to write utf8 for standard output in a way that works with python2 and python3 , and snapshoe's answer and Martijn Pieters helpful comment . Also setting the correct encoding when sending stdout pipeline in Python .
But I still don't see a clear “better” way, especially with regard to error handling, gracefully.
No one has answered this question yet.
See similar questions:
:
Source: https://habr.com/ru/post/1614647/More articles:График диаграммы Вороного с тремя точками, использующими R и трипак-пакет - rCheck for consecutive 12 weeks of sales 0 - sqlHow to configure a profile when running the s3cmd sync - s3cmdJavaScript Object.keys returns an empty array - javascriptWhat is the most reliable way to detect if a user logs in from a different device than usual? - securityr - document () crashes. Error in if (pkg $ package == "devtools") {: the argument is 0 - rCount to the first three consecutive empty columns - excelReduce roaming win32 Perl to as many files and bytes as possible - perlWin32 named pipes and message size limits - is the old 64K limit still applicable? - windowsМогу ли я создать приложение часов в Swift и добавить его в приложение iOS, которое не было встроено в swift? - iosAll Articles