使用encode方法即可,举例如下:
#-*-coding:utf-8-*- def save(re, name): file = open("index_cut.txt", "w") for k,v in re.items(): line = "filename :" + name + "\t" + k.encode("utf-8") + "\t" + str(v) + "\n" file.write(line) file.close() if __name__ == "__main__": result = {"清明": 1, "老师": 2, "天气": 3} save(result, "digit")
index_cut.txt: