我无法将字符串格式化为 utf-8 在此脚本中,我从 excel 文件中获取数据,然后循环打印出来,问题是带有特殊字符的字符串显示错误。
结果我不断得到“PatrÄ«cija”而不是“Patrīcija”似乎找不到解决这个问题的方法
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import xlrd
import datetime
def todaysnames():
todaysdate = datetime.datetime.strftime(datetime.date.today(), "%d.%m")
book = xlrd.open_workbook("vardadienas.xls")
sheet = book.sheet_by_name('Calendar')
for rownr in range(sheet.nrows):
if sheet.cell(rownr, 0).value == todaysdate:
string = (sheet.cell(rownr, 1).value)
string = string.encode(encoding="UTF-8",errors="strict")
names = string.split(', ')
return names
names = todaysnames()
for name in names:
print name