Defining utf8 encoding for all `.py` files
See original GitHub issue
Top Results From Across the Web
Working with UTF-8 encoding in Python source - Stack Overflow
In Python 3, UTF-8 is the default source encoding (see PEP 3120), so Unicode characters can be used anywhere. In Python 2, you...
Read more >Unicode HOWTO — Python 3.11.1 documentation
Usually this is implemented by converting the Unicode string into some encoding that varies depending on the system. Today Python is converging on...
Read more >A Guide to Unicode, UTF-8 and Strings in Python
UTF-8 : It uses 1, 2, 3 or 4 bytes to encode every code point. It is backwards compatible with ASCII. All English...
Read more >Unicode & Character Encodings in Python: A Painless Guide
This means that you don't need # -*- coding: UTF-8 -*- at the top of .py files in Python 3. All text (...
Read more >How to Use UTF-8 with Python (evanjones.ca)
Any ASCII-compatible encoding is permitted. For details, see the Defining Python Source Code Encodings specification. Other Resources. Using ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hopefully these will go away once the Python2.7 goes away. Closing the issue =)
If the user writes code with an import that uses non-ASCII characters, then yes, that file should declare its source encoding. But I don’t think it would help to declare the source encoding in files that are pure-ASCII.
The problem in #1024 seems to be the
unicode_literals
import.os.path.expanduser()
apparently assumes that the type of its argument—which, withunicode_literals
, isunicode
—matches the type of the environment variable, which isstr
(bytes in 2.7, unicode in 3.x). This mismatch in 2.7 is not a problem with all-ASCII strings, because an ASCII bytestring can be concatenated with a unicode string. But it fails if the bytestring is non-ASCII:Is the
unicode_literals
import really necessary? If so, then perhaps all literals passed toos.path
should be wrapped instr()
, effectively negatingunicode_literals
in 2.7.