python读取csv最后一行_python – 尝试使用seek()获取csv文件的最后一行时的AttributeError...
我試圖從csv文件返回最后一行.我正在修改我之前寫的另一個函數,它返回文本文件的最后一行.它似乎首先按預期工作,但現在當我調用該函數時它會拋出一個錯誤.
reader.seek(0, os.SEEK_END)
AttributeError: '_csv.reader' object has no attribute 'seek'
import os
import csv
def getLastFile(filename):
distance = 1024
with open(filename,'rb') as f:
reader = csv.reader(f)
reader.seek(0, os.SEEK_END)
if reader.tell() < distance:
reader.seek(0, os.SEEK_SET)
lines = reader.readlines()
lastline = lines[-1]
else:
reader.seek(-1 * distance, os.SEEK_END)
lines = reader.readlines()
lastline = lines[-1]
return lastline
有人可以幫我修改我的代碼嗎?我很確定你可以用這種方式使用搜索,也許我錯了?
總結
以上是生活随笔為你收集整理的python读取csv最后一行_python – 尝试使用seek()获取csv文件的最后一行时的AttributeError...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: mfc链表中的数据如何排序输出_java
- 下一篇: html伸缩布局,CSS3 伸缩布局(