I'm having trouble formating the strings to utf-8 In this script im getting data from excel file then printing it out in a loop, the problem is that the string with special characters shows up wrong.
In result I keep getting 'PatrÄ«cija' instead of 'Patrīcija' Can't seem to find the solution for this problem
#!/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
Changed encoding to iso8859_13(Baltic languages)
and it fixed it.