国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

python處理文本文件并生成指定格式的文件

2020-02-23 05:36:31
字體:
來源:轉載
供稿:網友
import os import sys import 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+"http://"+tmpFile     outFilePath = path+"http://BAK_"+tmpFile     inFileIns = getFileIns(inFilePath,inFileMod)     outFileIns = getFileIns(outFilePath,outFileMod)     getAndProc(inFileIns,outFileIns)     inFileIns.close()     outFileIns.close()
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 海阳市| 南投县| 开阳县| 洪江市| 伊通| 响水县| 翁牛特旗| 汝南县| 武强县| 敦煌市| 大足县| 报价| 余干县| 黔西县| 合阳县| 长宁县| 富阳市| 连江县| 滦平县| 保山市| 清河县| 营山县| 临邑县| 桃源县| 天气| 元朗区| 岳西县| 呼图壁县| 东莞市| 灵山县| 明光市| 乐平市| 建昌县| 伊春市| 隆化县| 年辖:市辖区| 肇庆市| 沿河| 广昌县| 绥滨县| 霍山县|