Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想创建一个像C:\sample\sample1\hello.py. sample它应该自动创建从to的完整路径hello.py,以及介于两者之间的所有目录。这在 Python 中可能吗?
C:\sample\sample1\hello.py
sample
hello.py
以下功能可能会有所帮助:
import os root_path = 'C:\path' folders = ['folder 01', 'folder 02', 'folder 03'] for folder in folders: os.mkdir(os.path.join(root_path, folder))