Python csv seek() not working -


hi trying read csv file using following code. want read n th line m th line of csv file provided. example want start reading 10th line 100 line , after start 500th line 1000th line. give parameters using start , end variables.

the problem it start beginning regardless start , end variables. tried , tried solution failed.can me figure out issue here.? lot! (there duplicate questions no 1 seems have given solution)

      import csv     import os      open('file.csv','r') csvfile:         start=10         end=100         csvfile.seek(start)         r= csv.reader(csvfile)         r.next()         in range(start,end):             try:                 url=r.next()[2]                 print url             except indexerror,e:                 print str(e),             except valueerror,b:                 print b         csvfile.close()  

use csv module.

import csv  n = 3 m = 5  read = 0 open("so.csv") csvfile:     reader = csv.reader(csvfile)     record in reader:         read += 1         if read >= n , read <= m:             print(record) 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -