当前位置: 代码迷 >> 综合 >> python批量创建txt文件
  详细解决方案

python批量创建txt文件

热度:15   发布时间:2024-03-08 14:07:53.0

  批量创建txt文件,并统一命名,在所有文件中写入要求的语句。

#文件个数
num=5def main():#txt文件的存放路径desktop_path = "C:\\Users\\Zhang\\Desktop\\aaa\\"count=0for i in range(num):#命名格式full_path = desktop_path + "blxw_" + str(count) + '.txt'file = open(full_path, 'w')#写入的语句file.write("hello world!")print(full_path)count+=1if __name__ == '__main__':main()

 

  相关解决方案