Implement usage of "with" statement on relevant IO operations.
[OpenColorIO-Configs.git] / aces_1.0.0 / python / aces_ocio / process.py
index ad0b02e..47b968f 100755 (executable)
@@ -39,11 +39,9 @@ def read_text(text_file):
          Return value description.\r
     """\r
 \r
-    if (text_file != ''):\r
-        fp = open(text_file, 'rb')\r
-        # Create a text/plain message\r
-        text = (fp.read())\r
-        fp.close()\r
+    if text_file != '':\r
+        with open(text_file, 'rb') as fp:\r
+            text = (fp.read())\r
     return text\r
 \r
 \r
@@ -62,11 +60,9 @@ def write_text(text, text_file):
          Return value description.\r
     """\r
 \r
-    if (text_file != ''):\r
-        fp = open(text_file, 'wb')\r
-        # Create a text/plain message\r
-        fp.write(text)\r
-        fp.close()\r
+    if text_file != '':\r
+        with open(text_file, 'wb') as fp:\r
+            fp.write(text)\r
     return text\r
 \r
 \r
@@ -309,16 +305,14 @@ class Process:
 \r
         if log_filename:\r
             try:\r
-                # This also doesn't seem like the best structure...\r
+                # TODO: Review statements.\r
                 # 3.1\r
                 try:\r
-                    log_handle = open(log_filename,\r
-                                      mode='wt',\r
-                                      encoding='utf-8')\r
+                    log_handle = (\r
+                        open(log_filename, mode='wt', encoding='utf-8'))\r
                 # 2.6\r
                 except:\r
-                    log_handle = open(log_filename,\r
-                                      mode='wt')\r
+                    log_handle = open(log_filename, mode='wt')\r
             except:\r
                 print('Couldn\'t open log : %s' % log_filename)\r
                 log_handle = None\r