stevenbeales
12/30/2018 - 7:55 PM

Read and write files

def read(file_location):
    with open(file_location, ’r+’, newline=’’) as csv_file:
        reader = csv.reader(csv_file)
        return [row for row in reader]
        
def write(file_location, rows):
    with open(file_location, ’w+’, newline=’’) as csv_file:
        writer = csv.writer(csv_file)
        for row in rows:
            writer.writerow(row)
            
csv.QUOTE_ALL: quotes every column, it doesn’t matter if they contain a delimiter character or not. • csv.QUOTE_MINIMAL: quotes only the columns which contains a delimiter character.
• csv.QUOTE_NONNUMERIC: quotes all non numeric columns. 
• csv.QUOTE_NONE: quotes nothing. It forces you to check whether or not the user inputs a delimiter character in a column, if you don’t, you will read an unexpected number of columns.