本文整理匯總了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