os.makedirs(path, exist_ok=False)
该语句可以建立用于迭代建立文件夹。exist_ok为bool值。当path不存在时,则会根据path迭代(划重点)的建立文件夹。当path存在时,若exist_ok为True时,则什么都不做,若为False,则会报文件夹已存在的错误。该语句可以很方便地替代以下语句:
if not os.path.exists(path):
os.mkdir(path)
os.makedirs(path, exist_ok=False)
该语句可以建立用于迭代建立文件夹。exist_ok为bool值。当path不存在时,则会根据path迭代(划重点)的建立文件夹。当path存在时,若exist_ok为True时,则什么都不做,若为False,则会报文件夹已存在的错误。该语句可以很方便地替代以下语句:
if not os.path.exists(path):
os.mkdir(path)