所以我有一些愛爾蘭語(蓋爾詞)的單詞列表,我想使用unicode,以便RDFlib能夠理解上面的一些重音符號字中的字母。我不知道是否在列表中或之後使用unicode。這裏是我的代碼至今:在文件如何在Python中使用帶有列表或字符串的unicode
樣品線= 00001740 n 3 eintiteas aonán beith 003 ~ 00001930 n 0000
def process_file(self):
self.file = open("testing_line_ir.txt", "r")
return self.file
def line_for_loop(self, file):
for line in file:
self.myline = unicode(line, 'utf-8')
for line in self.myline:
............here is where other processes are ran.......
這是給了錯誤:
UnicodeDecodeError: 'utf8' codec can't decode byte 0xe1 in position 26: invalid continuation byte
我也有試過這樣:
def get_words_list(self, word_part, num_words):
self.word = word_part[3:3 + num_words:1]
self.myword = [unicode(i) for i in self.word]
return self.myword
在這種情況下,'word'是單詞['eintiteas','aonán','beith']的列表,我嘗試使用g myword作爲編碼列表,具有與上述相同的錯誤。
編輯: 這裏是從發生錯誤的源代碼,它發生在graph.parse線 穿過像塊1和命名空間的變量是隻是文字
def compose_printout(self, namespaces, block1, block2, close_rdf):
self.printout += namespaces + block1 + block2 + close_rdf
self.tabfile = StringIO(self.printout)
return self.tabfile
def serialize(self, graph, tabfile):
""" This will serialize with RDFLib """
graph.parse(tabfile, publicID=None, format="xml")
其中的一些線字被添加到一個RDFlib圖,所以這裏的任何幫助將是偉大的!
您的輸入數據是**不是** UTF-8編碼。您需要找到用於文件數據的正確編解碼器。 –