Ich bekomme folgende Fehlermeldung:
Hier mein Code:Traceback (most recent call last):
File "C:\work\workspace\ChecktO_ol\src\ChecktO_ol.py", line 151, in <module>
frame = MainWindow(None, "ChecktO_ol")
File "C:\work\workspace\ChecktO_ol\src\ChecktO_ol.py", line 15, in __init__
self.checkson = word_test.CheckOr()
File "C:\work\workspace\ChecktO_ol\src\word_test.py", line 22, in __init__
self.common_formats = [x.lower().strip() for x in self.zeichen(str(self.root.xpath('common/text()')[0])).split(',')]
UnicodeEncodeError: 'ascii' codec can't encode character u'\xfc' in position 139: ordinal not in range(128)
Code: Alles auswählen
# -*- coding: utf-8 -*-
'''
Created on 03.02.2012
@author: szabop
'''
import win32com.client as win32, traceback
from lxml import etree
class CheckOr():
def __init__(self):
self.zeitschrift ="ZFR"
self.parser = etree.XMLParser(recover=True, resolve_entities=True, load_dtd=True)
self.formats_file = "formats.xml"
self.formats = etree.ElementTree(etree.XML(open(self.formats_file, 'r').read(),self.parser))
self.root = self.formats.getroot()
self.common_formats = [x.lower().strip() for x in self.zeichen(self.root.xpath('common/text()')[0]).split(',')]
self.numbered_formats = [x.lower().strip() for x in self.zeichen(self.root.xpath('numbered/text()')[0]).split(',')]
self.specific_formats = {}
for zs in self.root.xpath('zs'):
self.specific_formats[zs.xpath("zs_name/text()")[0]] = self.zeichen(zs.xpath("zs_formats/text()")[0]).split(',')
self.final_formats = self.common_formats + self.specific_formats[self.zeitschrift]
for i in range(1,20):
for item in self.numbered_formats:
self.final_formats.append(item + " %i" %i)
def zeichen(self, s):
return s.replace(u"ü","ue").replace(u"ä", "ae").replace(u"ß", "ss")
def main(self, file):
word = win32.gencache.EnsureDispatch('Word.Application')
doc = word.Documents.Open(file)
errors = []
p = 0
for par in doc.Paragraphs:
if not(self.zeichen(str(par.Format.Style)).lower().strip() in self.final_formats):
#print "WRONG: %s" % self.zeichen(str(par.Format.Style)).lower()
#print "P%i: %s" % (p+1,par)
errors.append([p+1,str(par).strip(),self.zeichen(str(par.Format.Style)).lower()])
p+=1
doc.Close()
word.Application.Quit(-1)
return errors
def getJournals(self):
return self.specific_formats.keys()
Vielen Dank im Vorraus !