Refactored io_util.write_file method.

This commit is contained in:
Fabio Caccamo 2019-10-14 16:32:40 +02:00
parent 51bb80c7b5
commit 73b72c4d63
1 changed files with 3 additions and 2 deletions

View File

@ -166,9 +166,10 @@ def read_url(url, *args, **kwargs):
def write_file(filepath, content): def write_file(filepath, content):
# https://stackoverflow.com/questions/12517451/automatically-creating-directories-with-file-output # https://stackoverflow.com/questions/12517451/automatically-creating-directories-with-file-output
if not os.path.exists(os.path.dirname(filepath)): filedir = os.path.dirname(filepath)
if not os.path.exists(filedir):
try: try:
os.makedirs(os.path.dirname(filepath)) os.makedirs(filedir)
except OSError as e: except OSError as e:
# Guard against race condition # Guard against race condition
if e.errno != errno.EEXIST: if e.errno != errno.EEXIST: