os.mkdir(path) returns OSError when directory does not exist

后端 未结 10 2278
挽巷
挽巷 2020-12-08 09:54

I am calling os.mkdir to create a folder with a certain set of generated data. However, even though the path I specified has not been created, the os.mkdi

10条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-08 10:17

    In Python 3.2 and above, you can use:

    os.makedirs(path, exist_ok=True)

    to avoid getting an exception if the directory already exists. This will still raise an exception if path exists and is not a directory.

提交回复
热议问题