def hanzi2pinyin(self, string=""):
result = []
if not isinstance(string, unicode):
string = string.decode("utf-8")
for char in string:
key = '%X' % ord(char)
result.append(self.word_dict.get(key, char).split()[0][:-1].lower())
return result
修改后的hanzi2pinyin函数:
def hanzi2pinyin(self, string=""):
result = []
if not isinstance(string, unicode):
string = string.decode("utf-8")
for char in string:
key = '%X' % ord(char)
if not self.word_dict.get(key):
result.append(char)
else:
result.append(self.word_dict.get(key, char).split()[0][:-1].lower())
return result
修改后的hanzi2pinyin函数可以避免中英文混合的情况下,英文丢失.