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.

classification
Title: The documentation of os.makedirs is misleading
Type: Stage:
Components: Documentation Versions: Python 3.0, Python 2.6
process
Status: closed Resolution: works for me
Dependencies: Superseder:
Assigned To: georg.brandl Nosy List: georg.brandl, mher
Priority: normal Keywords: patch

Created on 2009-03-28 14:16 by mher, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
makedirs.diff mher, 2009-03-28 14:16 The patch of the documentation
Messages (3)
msg84305 - (view) Author: Mher Movsisyan (mher) Date: 2009-03-28 14:16
The documentation of os.makedirs (http://docs.python.org/library/os.html?
highlight=makedirs#os.makedirs) is misleading. It states that os.makedirs raises an 
exception if the leaf directory already exists but it doesn't.

Lib/os.py:

136 def makedirs(name, mode=0777):
137     """makedirs(path [, mode=0777])
138 
139     Super-mkdir; create a leaf directory and all intermediate ones.
140     Works like mkdir, except that any intermediate path segment (not
141     just the rightmost) will be created if it does not exist.  This is
142     recursive.
143 
144     """
145     head, tail = path.split(name)
146     if not tail:
147         head, tail = path.split(head)
148     if head and tail and not path.exists(head):
149         try:
150             makedirs(head, mode)
151         except OSError, e:
152             # be happy if someone already created the path
153             if e.errno != errno.EEXIST:
154                 raise
155         if tail == curdir:           # xxx/newdir/. exists if xxx/newdir exists
156             return
157     mkdir(name, mode)

The attachment is a patch of the documentation (trunk, revision 70643).
msg85483 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2009-04-05 11:28
Actually, it works as documented:

>>> import os
>>> os.makedirs("/tmp")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.6/os.py", line 157, in makedirs
    mkdir(name, mode)
OSError: [Errno 17] File exists: '/tmp'
msg85511 - (view) Author: Mher Movsisyan (mher) Date: 2009-04-05 15:08
Sorry for confusion. I thought a "leaf directory" is an intermediate-level 
directory.

>>> import os
>>> os.makedirs("/tmp/a/b")
>>>
History
Date User Action Args
2022-04-11 14:56:47adminsetgithub: 49836
2009-04-05 15:08:16mhersetmessages: + msg85511
2009-04-05 11:28:43georg.brandlsetstatus: open -> closed
resolution: works for me
messages: + msg85483
2009-03-28 14:16:30mhercreate