def read_file(self, filename): if file_exists(filename): infile = open(filename, "r" ) while infile: line = infile.readline() if not line: infile.close() break else: self._put_in_line(line)
def read_file(self, filename): if file_exists(filename): infile = open(filename, "r") while infile: line = infile.readline() if not line: infile.close() break else: self._put_in_line(line)
def __init__(self, filename): ''' Initialises the required instance variables. Opens the input file (if possible) and calls the __read_file method. Throws an IOError exception if the file cannot be opened. ''' self.__filename = filename if file_exists(self.__filename): self.__file_handle = open(self.__filename, mode='r') self.__read_file() elif filename is not None: raise IOError("Could not open the specified list file, %s." % self.__filename)
def __init__(self, filename = None): ''' Initialises the abstract class. Calls self.__set_settings(), which repopulates self.settings and populates self.settings_types. If a valid filename is provided, we then call self.__read_settings_from_file() to open the file and read the configuration settings from there. ''' self.__config_parser = ConfigParser() self.__set_settings(self.settings) # Referring to our settings self.__config_type_method_dict = { str : self.__config_parser.get, bool : self.__config_parser.getboolean, int : self.__config_parser.getint, float : self.__config_parser.getfloat } if filename is not None: if not file_exists(filename): # File doesn't exist! raise IOError("Could not find the specified configuration file, %s." % (filename)) self.__read_settings_from_file(filename) # File does exist; attempt to read.
def __init__(self, filename=None): ''' Initialises the abstract class. Calls self.__set_settings(), which repopulates self.settings and populates self.settings_types. If a valid filename is provided, we then call self.__read_settings_from_file() to open the file and read the configuration settings from there. ''' self.__config_parser = ConfigParser() self.__set_settings(self.settings) # Referring to our settings self.__config_type_method_dict = { str: self.__config_parser.get, bool: self.__config_parser.getboolean, int: self.__config_parser.getint, float: self.__config_parser.getfloat } if filename is not None: if not file_exists(filename): # File doesn't exist! raise IOError( "Could not find the specified configuration file, %s." % (filename)) self.__read_settings_from_file( filename) # File does exist; attempt to read.