Enable Unicode Globally in Python

Can you not put this on every page?

 # -*- coding: utf-8 -*-

I would really like Python by default. Thanks in advance!

+3
source share
3 answers

In Python 3, the default encoding is UTF-8, so you no longer need to set it explicitly. However, there is no way to "globally" set the source encoding by default, and history has shown that such global parameters, as a rule, are a bad idea. (For example, the -U and -Q options for Python and sys.setdefaultencoding () returned when we had this.) You do not control (directly) the entire source that is imported into your program, since it includes a standard library and any third-party modules which you use directly or indirectly.

, Unicode, . , , UTF-8, , , ASCII unicode (, u'spæm'), . -unicode- ('spam' "spam") unicode, .

+9

Python 3.0

, Python 3, , 2.x

+1

Python 2, , dev. , - - - , UnicodeDecodeError s.

0
source

Source: https://habr.com/ru/post/1730904/


All Articles