[Python-bugs-list] [Bug #116720] function to open a file and create intermediate directories

noreply@sourceforge.net noreply@sourceforge.net
Thu, 12 Oct 2000 10:06:30 -0700


Bug #116720, was updated on 2000-Oct-12 09:24
Here is a current snapshot of the bug.

Project: Python
Category: Modules
Status: Closed
Resolution: Wont Fix
Bug Group: Feature Request
Priority: 5
Summary: function to open a file and create intermediate directories

Details: A function would be useful (maybe available in the
os module), that opens a file for writing and creates
all necessary intermediate directories. Here is the
Python function that does exactly that:

def forceopen(name, filemode, dirmode=0777):
    try:
        return open(name, filemode)
    except IOError, e:
       if e[0] != 2: # didn't work for some other reason
           raise
       lastsep = name.rfind(os.sep)
       if lastsep == -1:
           raise
       os.makedirs(name[:lastsep], dirmode)
       return open(name, filemode)


Follow-Ups:

Date: 2000-Oct-12 10:06
By: fdrake

Comment:
This seems too esoteric a function to include in the standard libraries.  Without some serious justification, I don't see why this should be added since it's simple enough to add to an application's utility libraries.
-------------------------------------------------------

For detailed info, follow this link:
http://sourceforge.net/bugs/?func=detailbug&bug_id=116720&group_id=5470