python文字檔,產生指定的檔案格式

來源:互聯網
上載者:User

標籤:

import osimport sysimport string#在一個特定的模式開啟指定的檔案,擷取檔案控制代碼def getFileIns(filePath,model):    print("開啟檔案")    print(filePath)    print(model)    return open(filePath,model)#擷取須要處理的檔案def getProcFile(path):    return os.listdir(path)#推斷是否滿足某個條件,假設滿足則運行def isTrue(outFileIns,s):    findStr1 = "LINE_COUNT_UPDATE      INTEGER := 0;"    writeStr1 = "LINE_COUNT_ERROR       INTEGER := 0;        --錯誤資料XX條"    findStr2 = "DBMS_OUTPUT.PUT_LINE('處理完成"    writeStr2 = "DBMS_OUTPUT.PUT_LINE('錯誤資料['||LINE_COUNT_ERROR||']條.');"    findStr3 = "DBMS_OUTPUT.PUT_LINE('插入資料['||CUR_RESULT.INT_ID||']時發生異常...');"    writeStr3 = "LINE_COUNT_ERROR := LINE_COUNT_ERROR+1;"    findStr4 = "DBMS_OUTPUT.PUT_LINE('更新資料['||CUR_RESULT.INT_ID||']時發生異常...');"        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\t\t\t"+writeStr3+"\n")    elif s.find(findStr4) != -1:        outFileIns.write(s)        outFileIns.write("\t\t\t\t\t"+writeStr3+"\n")    elif s.find("CS_OSLGIS") != -1:        outFileIns.write(s.replace("CS_OSLGIS","CQ_RMW"))    elif s.find("AND A.LONGITUDE >") != -1:        outFileIns.write("\t\t\tAND A.LONGITUDE IS NOT NULL\n\t\t\tAND A.LONGITUDE IS NOT NULL\n\t\t\tAND ROWNUM<2\n")    elif s.find(") LOOP") != -1:        outFileIns.write("\t\t) LOOP\n")    else:        outFileIns.write(s.replace("||')',2","||')',3"))                #讀取並處理文本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()            

著作權聲明:本文部落格原創文章。部落格,未經同意,不得轉載。

python文字檔,產生指定的檔案格式

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.