This section describes how to process text files in python and generate files in the specified format. For more information, see
Import OS import sys import string # Open the specified file in the specified mode and obtain the file handle def getFileIns (filePath, model): print ("Open File") print (filePath) print (model) return open (filePath, model) # obtain the file to be processed def getProcFile (path): return OS. listdir (path) # determine whether a condition is met. If yes, run def isTrue (outFileIns, s): findStr1 = "LINE_COUNT_UPDATE INTEGER: = 0;" writeStr1 = "LINE_COUNT_ERROR INTEGER: = 0; -- XX rows of Error Data "findStr2 =" DBMS_OUTPUT.PUT_LINE ('processed" WriteStr2 = "DBMS_OUTPUT.PUT_LINE ('error data ['| LINE_COUNT_ERROR |. '); "findStr3 =" DBMS_OUTPUT.PUT_LINE ('insert data [' | CUR_RESULT.INT_ID | '] An exception occurred... '); "writeStr3 =" LINE_COUNT_ERROR: = LINE_COUNT_ERROR + 1; "findStr4 =" DBMS_OUTPUT.PUT_LINE ('Update data [' | CUR_RESULT.INT_ID | '] An exception occurred... '); "if s. find (findStr1 )! =-1: outFileIns. write (s) outFileIns. write (writeStr1 + "\ n") elif s. find (findStr2 )! =-1: outFileIns. write (s) outFileIns. write (writeStr2 + "\ n") elif s. find (findStr3 )! =-1: outFileIns. write (s) outFileIns. write ("\ t" + writeStr3 + "\ n") elif s. find (findStr4 )! =-1: outFileIns. write (s) outFileIns. write ("\ t" + writeStr3 + "\ n") elif s. find ("CS_OSLGIS ")! =-1: outFileIns. write (s. replace ("CS_OSLGIS", "CQ_RMW") elif s. find ("and a. longpolling> ")! =-1: outFileIns. write ("\ t \ tAND. longpolling is not null \ n \ t \ tAND. longpolling is not null \ n \ t \ tAND ROWNUM <2 \ n ") elif s. find (") LOOP ")! =-1: outFileIns. write ("\ t) LOOP \ n") else: outFileIns. write (s. replace ("| ')', 2", "| ')', 3") # Read and process the text def getAndProc (inFileIns, outFileIns): lines = inFileIns. readlines () for s in lines: # print (s) isTrue (outFileIns, s) if _ name __= = "_ main __": inFileMod = "r" outFileMod = "w" path = "D :\\ rmsdata2gis" for tmpFile in OS. listdir (path): inFilePath = path + "\" + tmpFile outFilePath = path + "\ BAK _" + tmpFile inFileIns = getFileIns (inFilePath, inFileMod) outFileIns = getFileIns (outFilePath, outFileMod) getAndProc (inFileIns, outFileIns) inFileIns. close () outFileIns. close ()