Python tips: create path if not exist

--

Previously, I was using this way

import os
if not os.path.exists(directory):
os.makedirs(directory)

After reading this discussion, I’d like to use the following way

from pathlib import Path
Path("/my/directory").mkdir(parents=True, exist_ok=True)

--

--

No responses yet