如何在python中使用循环创建多个目录?
我想创建10个带有循环的目录,我尝试了以下代码:如何在python中使用循环创建多个目录?,python,loops,Python,Loops,我想创建10个带有循环的目录,我尝试了以下代码: import os pathname = 1 directory = "C:\Directory\Path\Name\\" + str(pathname) while pathname < 11: if not os.path.exists(directory): os.makedirs(directory) pathname += 1 导入操作系统 路径名=1 directory=“C:\dire
import os
pathname = 1
directory = "C:\Directory\Path\Name\\" + str(pathname)
while pathname < 11:
if not os.path.exists(directory):
os.makedirs(directory)
pathname += 1
导入操作系统
路径名=1
directory=“C:\directory\Path\Name\\”+str(路径名)
当路径名<11时:
如果不存在os.path.exists(目录):
os.makedirs(目录)
路径名+=1
但它只是创建了第一个目录并停止了,就好像它没有完成循环的其余部分一样。我对python相当陌生,这段代码对我来说很有意义,我不知道为什么它可能不起作用。非常感谢您的帮助 导入操作系统
import os
pathname = 1
directory = "C:\Directory\Path\Name\\" + str(pathname)
while pathname < 11:
if not os.path.exists(directory):
os.makedirs(directory)
pathname += 1
directory = "C:\Directory\Path\Name\\" + str(pathname)
路径名=1
directory=“C:\directory\Path\Name\\”+str(路径名)
当路径名<11时:
如果不存在os.path.exists(目录):
os.makedirs(目录)
路径名+=1
directory=“C:\directory\Path\Name\\”+str(路径名)
您需要更新loop@MooingRawr哇,太简单了。非常感谢!