读取文本最后一行: f = open('test11.txt', 'rb') for i in f: offset = -16 while True: f.seek(offset, 2) data = f.readlines() if len(data) > 1: print("文件的最后一行是:%s"%(data[-1].decode('gbk'))) break offset *= 2 优点: 使用for i in f是使用一行读取一行,不会消耗太多的内存,如果使用readl
1.写入excel,一开始不需要自己新建一个excel,会自动生成 attribute_proba是我写入的对象 import xlwt myexcel = xlwt.Workbook() sheet = myexcel.add_sheet('sheet') si=-1 sj=-1 for i in attribute_proba: si=si+1 for j in i: sj=sj+1 sheet.write(si,sj,str(j)) sj=-1 myexcel.save("attribut
C#创建记事本方法一://创建对象 FileStream stream = new FileStream(@"d:\aa.txt",FileMode.Create);//fileMode指定是读取还是写入 StreamWriter writer = new StreamWriter(stream); writer.WriteLine("123456");//写入一行,写完后会自动换行 writer.Write("abc");//写完后不会换行 w