-3

In python, if a file opened using the w access flag will the data written to file be:

  • ASCII-encoded
  • encoded using the UTF-8 scheme
  • encoded using some other scheme?

If it is platform or system specific, how do we find out which encoding scheme is used, or is there a different library I should use for file I/O for which we explicitly specify the encoding scheme?

file = open("data.txt", "w")
1
  • It does not depend on the file mode. Commented Mar 16, 2023 at 1:28

1 Answer 1

3

Per the open docs:

In text mode, if encoding is not specified the encoding used is platform-dependent: locale.getencoding() is called to get the current locale encoding.

You can always specify it manually mind you; that's what the optional encoding argument is for.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.