On 28Apr2023 10:39, Mats Wichmann <m...@wichmann.us> wrote:
For this specific case, you can use os.makedirs:
os.makedirs(dirname, exist_ok=True)
I'm not a great fan of makedirs because it will make all the missing
components, not just the final one. So as an example, if you've got a
NAS mounted backup area at eg:
/mnt/nas/backups/the-thing/backups-subdir
and your config file has this mistyped as:
/mn/nas/backups/the-thing/backups-subdir
and makedirs is used, then it will make the backup area on eg the root
drive where there's no room. (I'm looking at you, Docker, grr). There
are plenty of similar situations.
Because of this I usually am prepared to make a missing final component
with mkdir(), but not a potentially deep path with makedirs().
Cheers,
Cameron Simpson <c...@cskk.id.au>
--
https://mail.python.org/mailman/listinfo/python-list