From 7ed5d0972e52b9cfc0caedcba61774106f655543 Mon Sep 17 00:00:00 2001 From: Eric Blade Date: Wed, 16 Sep 2009 00:13:42 -0500 Subject: [PATCH] use with..as for file reading/writing, as we don't need 2.4 compat anyway right? --- pyfpdb/Configuration.py | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/pyfpdb/Configuration.py b/pyfpdb/Configuration.py index 1b2f47b4..61308641 100755 --- a/pyfpdb/Configuration.py +++ b/pyfpdb/Configuration.py @@ -24,6 +24,7 @@ Handles HUD configuration files. ######################################################################## # Standard Library modules +from __future__ import with_statement import os import sys import inspect @@ -444,12 +445,11 @@ class Config: def read_default_conf(self, file): parms = {} - fh = open(file, "r") - for line in fh: - line = string.strip(line) - (key, value) = line.split('=') - parms[key] = value - fh.close + with open(file, "r") as fh: + for line in fh: + line = string.strip(line) + (key, value) = line.split('=') + parms[key] = value return parms def find_example_config(self): @@ -498,14 +498,12 @@ class Config: def save(self, file = None): if file != None: - f = open(file, 'w') - self.doc.writexml(f) - f.close() + with open(file, 'w') as f: + self.doc.writexml(f) else: shutil.move(self.file, self.file+".backup") - f = open(self.file, 'w') - self.doc.writexml(f) - f.close + with open(self.file, 'w'): + self.doc.writexml(f) def edit_layout(self, site_name, max, width = None, height = None, fav_seat = None, locations = None):