Browse Source

[2298_7] use with-statement instead of try-except-finally statement

Naoki Kambe 12 years ago
parent
commit
ac64606707
1 changed files with 2 additions and 5 deletions
  1. 2 5
      src/bin/stats/stats_httpd.py.in

+ 2 - 5
src/bin/stats/stats_httpd.py.in

@@ -568,15 +568,12 @@ class StatsHttpd:
         string variable and returns string. Template object includes
         the variable. Limitation of a file size isn't needed there. XXXX"""
         lines = None
-        f = None
         try:
-            f = open(file_name, 'r')
-            lines = "".join(f.readlines())
+            with open(file_name, 'r') as f:
+                lines = "".join(f.readlines())
         except IOError as err:
             raise StatsHttpdDataError(
                 "%s: %s" % (err.__class__.__name__, err))
-        finally:
-            if f: f.close()
         return string.Template(lines)
 
 if __name__ == "__main__":