-
<PYTHON>파싱결과 비교(split count) --> 파일 저장Flower in my dev/Python 2015. 5. 29. 09:591234567891011121314151617181920212223242526272829303132333435363738394041424344import os, renPath = '경로/new_device'oPath = '경로/old_device'nList = os.listdir(nPath)oList = os.listdir(oPath)nList.sort()oList.sort()nFile = open('./flower_newcol.txt', 'w')oFile = open('./flower_oldcol.txt', 'w')nCheck = re.compile(r'flower_new\d*')oCheck = re.compile(r'flower_old\d*')for n in nList:if nCheck.search(n) != None:nFile.write(n + '\n')fPath = os.path.join(nPath, n)fRead = open(fPath, 'r')coList = fRead.readlines()for col in coList:s = col.split()cnt = len(s)nFile.write(str(cnt) + ' ')nFile.write('\n')else:passfor o in oList:if oCheck.search(o) != None:oFile.write(o + '\n')fPath = os.path.join(oPath, o)fRead = open(fPath, 'r')coList = fRead.readlines()for col in coList:s = col.split()cnt = len(s)oFile.write(str(cnt) + ' ')oFile.write('\n')else:pass
cs 파싱된 결과의 전체 라인을 읽어서
라인별로 slpit 후 길이를 비교하여 결과를 파일로 저장하는 스크립트
'Flower in my dev > Python' 카테고리의 다른 글
<PYTHON>[rrdtool 사용] (0) 2015.06.01 <PYTHON>[ConfigParser] (0) 2015.05.29 <PYTHON>파싱결과 비교(contents) --> 파일 저장 (0) 2015.05.29 <PYTHON>디렉토리 검색 및 xml 파싱 --> 파일 저장 (0) 2015.05.29 <PYTHON>[shutil] (0) 2015.05.28