seg1=''' <!DOCTYPE HTML> <html> <body> <meta charset=gb> <h2 align=center>Python成绩登记信计</h2> <table border='1' align="center" width=70%> <tr bgcolor='orange'> ''' seg2="</tr> " seg3="</table> <body> </html>" def fill_data(locls): seg='<st><td align="center">{}</td><td align="center"> {}</td><td align="center">{}</td><tdalign="center"> {}</td></tr> '.format(*locls) return seg fr=open("C:/Users/25764/Anaconda3/Lib/site-packages/itchat/components/Python成绩登记信计.csv","r") ls=[] for line in fr: line=line.replace(" ","") ls.append(line.split(",")) fr.close() fw=open("C:/Users/25764/Anaconda3/Lib/site-packages/itchat/components/Python成绩登记信计.csv.html","w") fw.write(seg1) fw.write('''<th width="25%">{}</th> <th width="25%">{}</th> <th width="25%">{}</th> <th width="25%">{}</th> '''.format(*ls[10])) fw.write(seg2) for i in range(len(ls)-1): fw.write(fill_data(ls[i+1])) fw.write(seg3) fw.close()