Reading csv file

I

Igor Korot

Hi, ALL,
Is there a better way to do that:

def Read_CSV_File(filename):
file = open(filename, "r")
reader = csv.DictReader(file)
line = 1
for row in reader:
if line < 6:
reader.next()
line++
# process the CSV

Thank you.
 
B

Bernd Nawothnig

Hi, ALL,
Is there a better way to do that:

def Read_CSV_File(filename):
file = open(filename, "r")
reader = csv.DictReader(file)
line = 1
for row in reader:
if line < 6:
reader.next()
line++
# process the CSV

#v+
def Read_CSV_File(filename):
with open(filename) as f:
for line,row in enumerate(csv.DictReader(f)):
if line >= 6:
# process the CSV
#v-




Bernd
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,772
Messages
2,569,593
Members
45,111
Latest member
VetaMcRae
Top