我想将datetime.ctime()值转换为Unicode。将datetime.ctime()值转换为Unicode
使用Python 2.6.4在Windows下运行我可以在我的区域设置为西班牙语象下面这样:
>>> import locale >>> locale.setlocale(locale.LC_ALL, 'esp')
然后我可以传给%A,%A,%B,并%B至CTIME()来获取日期和月份名称和缩写。
>>> import datetime >>> dateValue = datetime.date(2010, 5, 15) >>> dayName = dateValue.strftime('%A') >>> dayName 's\xe1bado'
如何将's \ xe1bado'值转换为Unicode?具体使用什么编码?
我在想我可能会做类似以下的事情,但我不确定这是否正确。
>>> codePage = locale.getdefaultlocale()[ 1 ] >>> dayNameUnicode = unicode(dayName, codePage) >>> dayNameUnicode u's\xe1bado'
马尔科姆
那*的* unicode的,你只是打印字节,而不是字符。 – 2010-05-18 22:48:37