本文整理汇总了Python中_locale.CODESET属性的典型用法代码示例。如果您正苦于以下问题:Python _locale.CODESET属性的具体用法?Python _locale.CODESET怎么用?Python _locale.CODESET使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类_locale
的用法示例。
在下文中一共展示了_locale.CODESET属性的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getpreferredencoding
# 需要导入模块: import _locale [as 别名]
# 或者: from _locale import CODESET [as 别名]
def getpreferredencoding(do_setlocale=True):
assert not do_setlocale
result = _locale.nl_langinfo(_locale.CODESET)
if not result and sys.platform == 'darwin':
# nl_langinfo can return an empty string
# when the setting has an invalid value.
# Default to UTF-8 in that case because
# UTF-8 is the default charset on OSX and
# returning nothing will crash the
# interpreter.
result = 'UTF-8'
return result
示例2: getpreferredencoding
# 需要导入模块: import _locale [as 别名]
# 或者: from _locale import CODESET [as 别名]
def getpreferredencoding(do_setlocale=True):
assert not do_setlocale
if sys.flags.utf8_mode:
return 'UTF-8'
result = _locale.nl_langinfo(_locale.CODESET)
if not result and sys.platform == 'darwin':
# nl_langinfo can return an empty string
# when the setting has an invalid value.
# Default to UTF-8 in that case because
# UTF-8 is the default charset on OSX and
# returning nothing will crash the
# interpreter.
result = 'UTF-8'
return result