无法创建文件记事本txt utf-8

时间:2019-02-26 06:42:11

标签: python python-3.x

我创建了文件,但是它仍然是ANSI而不是utf-8。请帮我谢谢

  import os

  def create_text_file(forder_path, count):
      for i in range(count): 
         name =  "{}.txt".format(i + 1)
         text_file = os.path.join(forder_path, name)
         with open(text_file, "w", encoding="UTF-8") as file:
            pass



  count = int(input("n count:"))
  create_text_file("C:/Users/m/Desktop/n/Text1", count)

1 个答案:

答案 0 :(得分:0)

阅读以下here。这是一个玩具示例:

import codecs
...
with codecs.open(file_path,'w','utf-8-sig') as writer:
   writer.write("Start of string\n")
   writer.write(u"This is a unicode character έ\n")
   writer.write(u"or encoded as \u03AD")