python os mkdir if not exists

没有找到与「python os mkdir if not exists」相关的内容

AI 回答 由 glm-4-flash 生成 · 仅供参考,请自行核实
1. 使用`os.path.exists()`检查目录是否存在。
2. 如果不存在,使用`os.makedirs()`创建目录。
3. 示例代码:

import os

path = 'new_directory'
if not os.path.exists(path):
os.makedirs(path)
没有找到「python os mkdir if not exists」相关的内容

建议:检查关键词是否有错别字,或换一个更常见的说法。