Posted By

fnurl on 04/05/09


Tagged

FileSystem


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

danielalexwood


Create directories needed to write a file


 / Published in: Python
 

URL: http://stackoverflow.com/questions/273192/python-best-way-to-create-directory-if-it-doesnt-exist-for-file-write/273679

  1. def ensure_dir(f):
  2. d = os.path.dirname(f)
  3. if not os.path.exists(d):
  4. os.makedirs(d)

Report this snippet  

You need to login to post a comment.