0

I understand enumerate is better to use when it is needed to read a specific line from a large file, because it uses next(), can the same be done with csv.reader()?

Edit: the file in question is a CSV file

Ébe Isaac
  • 11,563
  • 17
  • 64
  • 97
Priyank
  • 1,513
  • 1
  • 18
  • 36
  • Do you want to read each line of your file ? – Chr Nov 15 '16 at 14:34
  • No, I want to get to the i th line quickly, using the least possible memory – Priyank Nov 15 '16 at 14:37
  • 3
    check this out: http://stackoverflow.com/questions/30713181/how-to-find-specific-row-in-python-csv-module – Nikos Tavoularis Nov 15 '16 at 14:39
  • 1
    @NikosTavoularis How can i avoid reading the whole file in at once though? – Priyank Nov 15 '16 at 14:46
  • I dunno if you can avoid this, probably someone else may answer this, but with a quick search I found this old post where the the guy who provides the answer says that you cannot avoid it: http://stackoverflow.com/questions/3215347/subscripting-a-specific-line-from-pythons-csv-reader – Nikos Tavoularis Nov 15 '16 at 14:54
  • @NikosTavoularis Thanks a lot! I do believe enumerate reads the file line by line until the desired line is found, [link](http://stackoverflow.com/questions/2081836/reading-specific-lines-only-python) , so i guess that's the only way – Priyank Nov 15 '16 at 15:06

0 Answers0