This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author plakhotich
Recipients plakhotich, r.david.murray
Date 2015-11-08.20:16:39
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
Of course in examples I create '.' by hand, but in real code such things are
mostly automatic. Assume, for example, that you have a function for downloading

def download_file(url, save_as):
  # Before saving, you must ensure that path exists:
  os.makedirs(os.path.dirname(save_as), exist_ok=True)

os.path.abspath is not a solution, because, as it was mentioned, mkdir with
adrive name gives the same result:
d:\>mkdir d:\\
Access is denied.

Anyway, skipping the calls must be a job of exist_ok=True, otherwise it has
any sense.

By the way, do not pay attention to my second message(msg254341): as I said
at first, mkdirs shouldn't use e.errno at all. Because, as said in docstring,
makedirs must first check whether a folder exists, and only then call mkdir.
But currently it works in reverse order, which, in essence, is the source
of the problem.

I don't know why it was done that way, because if you try "timeit"
"try->mkdir->except" vs "if not isdir->mkdir", you will see that the second
is much faster (x3 (!) times on Windows, x0.7 times on Linux (on ext4 partition)
on my machine).

So the best solution is the most straightforward - to replace try-except block with:
  if not path.isdir(name):
      mkdir(name, mode)
Date User Action Args
2015-11-08 20:16:39plakhotichsetrecipients: + plakhotich, r.david.murray
2015-11-08 20:16:39plakhotichsetmessageid: <>
2015-11-08 20:16:39plakhotichlinkissue25583 messages
2015-11-08 20:16:39plakhotichcreate