1. 判断是否存在某个文件夹(path)函数:
函数:
def check_mkdir(dir_name):
if not os.path.exists(dir_name):
os.makedirs(dir_name)
判断语句:
check_mkdir(path)
2.判断是否存在某个文件夹(path):是则跳过,否则创建这个文件夹
os.makedirs(path, exist_ok=True)
该文介绍了两个Python方法来判断文件夹是否存在。如果不存在,第一个方法`check_mkdir`会创建它;第二个方法`os.makedirs`带有`exist_ok=True`参数,会跳过已存在的文件夹,避免重复创建。
1. 判断是否存在某个文件夹(path)函数:
函数:
def check_mkdir(dir_name):
if not os.path.exists(dir_name):
os.makedirs(dir_name)
判断语句:
check_mkdir(path)
2.判断是否存在某个文件夹(path):是则跳过,否则创建这个文件夹
os.makedirs(path, exist_ok=True)
2022

被折叠的 条评论
为什么被折叠?