Validating Data Before Writing

Mon 10 August 2026
import csv

def validate_row(row):
    return all(row)

data = [
    ["John", 28, "Toronto"],
    ["", 35, "Berlin"]
]

with open("validated.csv", "w", newline="") as file:
    writer = csv.writer(file)
    for row in data:
        if validate_row(row):
            writer.writerow(row)


Score: 10

Category: chapter11_csv_handling

Read More
Page 18 of 20

« Prev Next »