From: Naoki Kambe Date: Tue, 6 Nov 2012 12:01:31 +0000 (+0900) Subject: [2298_7] use with-statement instead of try-except-finally statement X-Git-Tag: trac2487_base~1^2~26^2~3 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ac646067077f60b99e70153e9896e2e7062f080c;p=thirdparty%2Fkea.git [2298_7] use with-statement instead of try-except-finally statement --- diff --git a/src/bin/stats/stats_httpd.py.in b/src/bin/stats/stats_httpd.py.in index fd69d8b676..e76bcbe0de 100644 --- a/src/bin/stats/stats_httpd.py.in +++ b/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__":