5 ms·
The Python source code is utf-8 by default in Python 3. But it says nothing about a character encoding used to save to a file. It is locale-dependent by default
by d0mine 2y ago
The Python source code is utf-8 by default in Python 3. But it says nothing about a character encoding used to save to a file. It is locale-dependent by default.
# string literals create str objects using utf-8 by default
Path("filenames use their own encoding").write_text("file content encoding uses yet another encoding")
The corresponding encodings are:
- utf-8 [tokenize.open]
- sys.getfilesystemencoding() [os.fsencode]
- locale.getpreferredencoding() [open]