是否有任何python“utf-8”字符串常量?

And*_*iuc 8 python encoding utf-8

我想使用“utf-8”字符串常量,因为在“UTF-8”、“UTF8”、“utf8”、“utf-8”、“utf-8”、“utf_8”之间进行选择总是让我感到困惑”

python 文档中的所有代码示例的语法如下:

with io.open("/tmp/a.txt", "w", encode="utf-8") as file_cursor:
    file_cursor.write(text)
Run Code Online (Sandbox Code Playgroud)

有人可以告诉我为什么会这样,也许是一些最佳实践,zends ...?

我想在 IDE 中使用代码建议来实现以下目标:

with io.open("/tmp/a.txt", "w", encode=ENCODINGS.UTF8) as file_cursor:
    file_cursor.write(text)  
Run Code Online (Sandbox Code Playgroud)

python核心中是否有任何开箱即用的标准常量?

Sim*_*ser 8

你可以使用:

import encodings

encodings.utf_8.getregentry().name
Run Code Online (Sandbox Code Playgroud)

这给'utf-8'.