I have a potentially very large csv file that I need to read in and display, but only a few records at a time. I want to be abe to page thru the file using offset and records variables.
What I have is the following, but it really doesnt work well at all and if I hit the end of the file it errors:
def showMail(self,offset,records):
"""
read in N lines of mail items
"""
mails = []
ifile = open('some.csv', "r")
data = csv.reader(ifile ,delimiter=',', quoting=csv.QUOTE_ALL)
if offset > 0:
for i in range(0,((offset*records)+records)):
if i > (offset*records)-1:
mails.append(data.next())
else:
data.next()
else:
for i in range(0,records):
mails.append(data.next())
ifile.close()
return mails
Is there a better way of doing this that I am just too new to know?
Thanks