我有两个Python字典,包含有关日语单词和字符的信息:
vocab:有效,以日语打印
v(for循环中词汇的一个字符):�
test(查找汉字字典中的字符):无
在我看来,for循环弄乱了编码。
我尝试了各种函数(decode、encode等),但迄今为止没有运气。
你有什么办法能让这个程序工作起来吗?
非常感谢你的帮助。
- vocabDic : contains vocabulary, key: word, value: dictionary with information about it
kanjiDic : contains kanji ( single japanese character ), key: kanji, value: dictionary with information about it
Now I would like to iterate through each character of each word in the vocabDic and look up this character in the kanji dictionary. My goal is to create a csv file which I can then import into a database as join table for vocabulary and kanji.
My Python version is 2.6
My code is as following:kanjiVocabJoinWriter = csv.writer(open('kanjiVocabJoin.csv', 'wb'), delimiter=',', quotechar='|', quoting=csv.QUOTE_MINIMAL) kanjiVocabJoinCount = 1 #loop through dictionary for key, val in vocabDic.iteritems(): if val['lang'] is 'jpn': # only check japanese words vocab = val['text'] print vocab # loop through vocab string for v in vocab: test = kanjiDic.get(v) print v print test if test is not None: print str(kanjiVocabJoinCount)+','+str(test['id'])+','+str(val['id']) kanjiVocabJoinWriter([str(kanjiVocabJoinCount),str(test['id']),str(val['id'])]) kanjiVocabJoinCount = kanjiVocabJoinCount+1
vocab:有效,以日语打印
v(for循环中词汇的一个字符):�
test(查找汉字字典中的字符):无
在我看来,for循环弄乱了编码。
我尝试了各种函数(decode、encode等),但迄今为止没有运气。
你有什么办法能让这个程序工作起来吗?
非常感谢你的帮助。
from __future__ import unicode_literals
? - utdemir