繁体   English   中英

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

[英]cannot create file notepad txt utf-8

我创建了文件,但它仍然是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)

这里阅读以下内容。 这是一个玩具示例:

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")

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM