←back to thread

238 points GalaxySnail | 1 comments | | HN request time: 0s | source
Show context
Euphorbium ◴[] No.40170122[source]
I thought it was default since python 3.
replies(2): >>40170798 #>>40173404 #
1. d0mine ◴[] No.40173404[source]
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]