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

python保存文字到文件中

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-12-12
  • 2021-06-12
  • 2021-07-24
  • 2022-12-23
  • 2021-06-12
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-01-06
  • 2021-08-24
  • 2022-12-23
  • 2022-02-11
相关资源
相似解决方案