利用xlwt库,将文件传输日志中的数据统计到表格中,生成易观测的折线图。
```python
import xlwt
import os
def set_style(name,height,bold=False):
style = xlwt.XFStyle()
font = xlwt.Font()
font.name = name
font.bold = bold
font.color_index = 4
font.height = height
style.font = font
return style
def write_excel():
filename = "/mnt/put_1.log"
f = xlwt.Workbook()
colum0 = []
colum1 = []
temp = []
sheet1 = f.add_sheet("auto-excel",cell_overwrite_ok = True)
row0 = ["time(s)","speed(kbyte/s)"]
f1 = open(filename)
line = f1.readline()
while line:
temp = line.split(',')
colum0.append(temp[0])
colum1.append(temp[1])
line = f1.readline()
f1.close()
for i in range(0,len(row0)):
sheet1.write(0,i,row0[i],set_style('Times New Roman',220,True))
for i in range(0,len(colum0)):
sheet1.write(i+1,0,colum0[i],set_style('Times New Roman',220,True))
for i in range(0,len(colum1)):
sheet1.write(i+1,1,colum0[i],set_style('Times New Roman',220,True))
f.save('test.xls')
if _name_ == '_main_':
write_excel()