txt文本变成html

file_name = 'x.txt'

f = open(file_name,'r')

file_result = 'x.html'

str_head = "

LINE CI UTIL"

str_head_1 = '

'

str_table = "

"

str_table_1 = '

'

str_tr = ''

str_tr_1 = ''

str_th = ''

str_th_1 = ''

html_total = ''

for line in f:

line_strip = line.strip('\n')

line_ci = line_strip.split(',')[0]

in_util = str(line_strip.split(',')[1])

out_util = str(line_strip.split(',')[2])

util = line_strip.split(',')[3]

html_str = str_tr+str_th+line_ci+str_th_1+str_th+in_util+str_th_1+str_th+out_util+str_th_1+str_th+util+str_th_1

html_total = html_total + html_str

title_str = str_tr+str_th+'line_ci'+str_th_1+str_th+'in_util'+str_th_1+str_th+'out_util'+str_th_1+str_th+'util'+str_th_1

html_result = str_head+str_head_1+str_table + title_str +html_total +str_table_1

f_result = open(file_result,'w')

f_result.write(html_result)

f_result.close()

上一篇:C# 计时器的三种使用方法


下一篇:jQuery源码分析-02正则表达式-RegExp-常用正则表达式