From 73b72c4d6332b8edd4bd70cdf178de6afa912886 Mon Sep 17 00:00:00 2001 From: Fabio Caccamo Date: Mon, 14 Oct 2019 16:32:40 +0200 Subject: [PATCH] Refactored io_util.write_file method. --- benedict/utils/io_util.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/benedict/utils/io_util.py b/benedict/utils/io_util.py index c2332ab..abcd52c 100644 --- a/benedict/utils/io_util.py +++ b/benedict/utils/io_util.py @@ -166,9 +166,10 @@ def read_url(url, *args, **kwargs): def write_file(filepath, content): # 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: - os.makedirs(os.path.dirname(filepath)) + os.makedirs(filedir) except OSError as e: # Guard against race condition if e.errno != errno.EEXIST: