9951 explained code solutions for 126 technologies


pythonHow to open CSV file


import csv

with open('file.csv') as f:
  reader = csv.reader(f)

  for row in reader:
    print(row)ctrl + c
csv

module to manipulate CSV

file.csv

path to CSV file

csv.reader

parses CSV from given file handler

for row in reader

iterate through all rows in CSV


Usage example

import csv

with open('/var/www/examples/file.csv') as f:
  reader = csv.reader(f)

  for row in reader:
    print(row)
output
['a', 'b', 'c']
['1', '2', '3']
['1', '3', '5']