예제 #1
0
 def dictReader(self):
     ''' Read entire csv file to 'dictionary reader object'.
     The object is somewhat similar to an array of dictionaries, 1 dict per row
     '''
     self.isError = True
     self.fileAsDict = None
     try:
         dictReaderObj = csv.DictReader(self.csvFileObj, delimiter=',', quotechar='"')
     except Exception, exArg:
         print "Exception type = " + type(exArg)
         log.userl.critical(
             'ERROR while Attempting to read CSV formatted parameter file: %s' % fileRef)
         log.userl.critical('read CSV error: %s' % exArg)
         appRoutines.appABEND()     # abort program
예제 #2
0
    def open(self, fileRef):
        """ Open :fileRef: with read mode.
        When successful creates csvFileObj (internal reference to opened file)
        """
        def _attemptingMsg():
            log.userl.critical(
                'ERROR while Attempting to open parameter file: %s' % fileRef)
        #----------------------------------------------------

        self.csvFileRef = fileRef
        self.isOK = False
        try:
            self.csvFileObj = open(fileRef, 'rb')
        except ValueError as exArg:
            _attemptingMsg()
            log.userl.critical('ValueError:  %s' % exArg)
            appRoutines.appABEND()     # abort program
        except IOError as exArg:
            _attemptingMsg()
            log.userl.critical('IOError:  %s' % exArg)
            appRoutines.appABEND()     # abort program
        except Exception, exArg:
            _attemptingMsg()
            log.userl.critical('Unexpected error type encountered: %s' % exArg)
            appRoutines.appABEND()     # abort program