Utf16 vs utf-16

Which line below is correct? Do I know all of these encodings available?

with open(filename, 'w', encoding='utf16') as fp:
with open(filename, 'w', encoding='utf-16') as fp:
+4
source share
1 answer

Interest Ask. I did some searches, and it looks like you can find all the options available here: https://docs.python.org/3/library/codecs.html#standard-encodings

therefore, in this case, not one! It should be utf_16. However, with my experience with python, I would not be surprised if they will sanitize the argument you provided so that it works independently. And from the link, it looks like they are doing! therefore utf-16must be a valid alias.

, , , ; , , 'utf-8' 'utf_8'

- . https://docs.python.org/3.4/library/functions.html#open, open,

. .

+3

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


All Articles