Python Question

Python: execute for loop only once(not the first time but second time)?

fileInput consists of a csv file with some 30 rows and I want to access only the second row.

for row in csv.reader(fileInput):


I need to access the second row not the first one(first one contains col names).
row[1]
gives second column in
row0
?

only the second row not from the second row!

Answer

You might want to consider using DictReader. It'll handle the header for you and allow you to access the columns by name rather than index (which can help with keeping code readable).

eg.

import csv

with open('names.csv') as csvfile:
    reader = csv.DictReader(csvfile)
    row = next(reader)
    print(row['first_name'], row['last_name'])