-
<PYTHON>디렉토리 검색 및 xml 파싱 --> 파일 저장Flower in my dev/Python 2015. 5. 29. 09:5412345678910111213141516171819202122232425262728293031323334353637383940414243444546import os, sysfrom bs4 import BeautifulSoupsaveList = []cnt01 = 0cnt02 = 0newPath = '경로/new_device'oldPath = '경로/old_device'nFile = 'flower_new'oFile = 'flower_old'nList = os.listdir(newPath)oList = os.listdir(oldPath)nFull = os.path.join(newPath, nFile)oFull = os.path.join(oldPath, oFile)for n in nList:tmpPath = nFull + str(cnt01)nWrite = open(tmpPath, 'w')f = open(os.path.join(newPath, n))xml = f.read()fSoup = BeautifulSoup(xml, 'xml')tmp = '[New Device Column]=====Sequence Number : ' + str(cnt01) + '\n'nWrite.write(tmp)for col in fSoup.findAll('measTypes'):nWrite.write(col.string + '\n')f.close()nWrite.close()cnt01 += 1for o in oList:tmpPath = oFull + str(cnt02)oWrite = open(tmpPath, 'w')f = open(os.path.join(oldPath, o))xml = f.read()fSoup = BeautifulSoup(xml, 'xml')tmp = '[Old Device Column]=====Sequence Number : ' + str(cnt02) + '\n'oWrite.write(tmp)for col in fSoup.findAll('measTypes'):oWrite.write(col.string + '\n')f.close()oWrite.close()cnt02 += 1
cs 디렉토리 두 곳에 존재하는 xml파일을 파싱하여
결과값을 파일에 저장하는 스크립트
'Flower in my dev > Python' 카테고리의 다른 글
<PYTHON>파싱결과 비교(split count) --> 파일 저장 (0) 2015.05.29 <PYTHON>파싱결과 비교(contents) --> 파일 저장 (0) 2015.05.29 <PYTHON>[shutil] (0) 2015.05.28 <PYTHON>[StringIO] (0) 2015.05.28 <PYTHON> twisted log 사용 (0) 2015.05.27