Objects

Files


with open('the_file.txt', 'r') as f:
    for line in f:
        # do stuff

CSV

import csv

def sample_open_csv(filename):
  with open(filename) as csv_file:
    f = csv.reader(csv_file)
    next(f, None) # skip the header row
    for row in f:
        print(row)

DictReader

import csv

def sample_open_csv(filename):
  with open(filename) as csv_file:
    f = csv.DictReader(csv_file)
    # _don't_ call next
    for row in f:
        print(row)

Topics for later: