for name in range(1,11): #循环创建10个文本文件
file_path='d://pyhello/' #绝对路径
my_file=file_path+str(name)+'.txt' #文件命名
file=open(my_file,'w') #创建文件
file.close() #创建一个关闭一个,不然会在内存中一直存在
python在特定目录创建多个特定文件的方法。
![](https://img-home.csdnimg.cn/images/20240711042549.png)
for name in range(1,11): #循环创建10个文本文件
file_path='d://pyhello/' #绝对路径
my_file=file_path+str(name)+'.txt' #文件命名
file=open(my_file,'w') #创建文件
file.close() #创建一个关闭一个,不然会在内存中一直存在