hedgehogues Asked:2024-05-29 04:32:10 +0000 UTC2024-05-29 04:32:10 +0000 UTC 2024-05-29 04:32:10 +0000 UTC 如何在Python中创建一个目录并缺少父目录? 772 如何在给定路径处创建目录,并在此路径处创建缺失的父目录,例如 Bash 命令的作用mkdir -p /path/to/nested/directory: python 1 个回答 Voted Best Answer Kromster 2024-05-29T16:28:36Z2024-05-29T16:28:36Z 从 python 3.2 开始,你可以这样做: import os os.makedirs('dir/subdir/subsubdir', exist_ok=True) 从 python 3.4 开始(现在有 pathlib 模块): from pathlib import Path path = Path('/home/dail/first/second/third') path.mkdir(parents=True) 从 python 3.5 开始,还有mkdir一个标志exist_ok: path.mkdir(parents=True, exist_ok=True) *基于https://stackoverflow.com/questions/6004073
从 python 3.2 开始,你可以这样做:
从 python 3.4 开始(现在有 pathlib 模块):
从 python 3.5 开始,还有
mkdir一个标志exist_ok:*基于https://stackoverflow.com/questions/6004073