"인문지식 처리와 프로그래밍2020 4.09"의 두 판 사이의 차이

soook
이동: 둘러보기, 검색
(새 문서: ==parser.py(한송이 국화꽃 파싱프로그램)== <pre> #!/usr/bin/python #-*- coding: utf-8 -*- import sys import webbrowser def writeHtml( template, output, table, lines ):...)
(차이 없음)

2020년 4월 9일 (목) 18:18 판


parser.py(한송이 국화꽃 파싱프로그램)

#!/usr/bin/python
#-*- coding: utf-8 -*-

import sys
import webbrowser

def writeHtml( template, output, table, lines ):
	
	f = open( template, 'r', encoding='utf-8')
	h = open( output, 'w+', encoding='utf-8')	
	
	while 1:
		line = f.readline()
		if not line: break
		if( '#YourData' == line.strip() ):
			h.write( '\t\n' )
			for m in range(lines):
				h.write( '\t\t' )		
				for n in range(10):
					h.write( ''.format( table[m][n] ) )
				h.write( '\n' )
			h.write( '\t
{0}
\n' )

else: h.write( '{0}\n'.format( line ) )

h.close() f.close()

def main(): #

try: filename = sys.argv[1] except: return

list = filename+'.lst' output = filename+'.htm'

f = open( list, 'r', encoding='utf-8')

row = [] lines = 0

while 1: text = f.readline() if not text: break

row.append( [[] for i in range(10)] ) parsed = text.split(sep=' ')

j = 0 for x in parsed: if( j < 10 ): row[lines][j] = x.strip() j = j + 1

lines = lines + 1

f.close()

writeHtml( 'templateTbs.htm', output, row, lines ) webbrowser.open_new_tab( output )

main()


<pre>