From 748fef44034daa3bb3636d3a293a7d42b86b4132 Mon Sep 17 00:00:00 2001 From: Marcus Stoegbauer Date: Sun, 13 Jan 2013 21:30:48 +0000 Subject: [PATCH] Init confobj before using it only read config file once --- userconfig/cfgfile.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/userconfig/cfgfile.py b/userconfig/cfgfile.py index f4fe18e..de7f41c 100644 --- a/userconfig/cfgfile.py +++ b/userconfig/cfgfile.py @@ -10,15 +10,16 @@ cfgfile.py Created by Marcus Stoegbauer on 2013-01-12. Copyright (c) 2013 __MyCompanyName__. All rights reserved. """ -from ConfigParser import ConfigParser +import ConfigParser class Conf(object): - confobj = ConfigParser() + confobj = ConfigParser.RawConfigParser() cfgfile = '' def __init__(self, filename = None): """if filename is set, open config file and initialize the ConfigParser """ + self.confobj = ConfigParser.RawConfigParser() if filename: self.setfilename(filename) # if filename @@ -27,7 +28,8 @@ class Conf(object): def setfilename(self, filename): """initialize the ConfigParser """ - if len(self.confobj.read(filename)) == 0 or self.confobj.read(filename)[0] != filename: + ret = self.confobj.read(filename) + if len(ret) == 0 or ret[0] != filename: raise Exception('Cannot read config file ' + filename) # if cannot read self.cfgfile = filename