使用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:

 

posted on 2018-04-07 10:38  当太阳不再发光  阅读(11346)  评论(0编辑  收藏  举报