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

时间:2017-05-22 09:20:59

标签: 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)

有人能告诉我为什么会这样,也许是一些最佳实践,热情......?

我想在IDE中使用代码建议来实现类似:

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

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

1 个答案:

答案 0 :(得分:2)

您可以使用:

import encodings

encodings.utf_8.getregentry().name

给出了'utf-8'