Python提供了locale模块来实现国际化,这个模块提供了到C的本地化功能的一个接口,还提供了一些方法,基于当前的locale来转换数字和字符串。
使用locale模块来格式化数据
#! /usr/bin/env python
#coding=utf-8
import locale
print "locale", "=>", locale.setlocale(locale.LC_ALL, "")
for k, v in info.items():
print k, v
#coding=utf-8
import locale
print "locale", "=>", locale.setlocale(locale.LC_ALL, "")
for k, v in info.items():
print k, v
使用locale模块得到平台locale
#! /usr/bin/env python
#coding=utf-8
import locale
language, encoding = locale.getdefaultlocale()
print "language", language
print "encoding", encoding
#coding=utf-8
import locale
language, encoding = locale.getdefaultlocale()
print "language", language
print "encoding", encoding