import csv


def load_percepts(filename):
    """Load percepts from a CSV file."""
    f = None
    try:
        f = open(filename, "r")
        percepts = []
        for row in csv.reader(f):
            if not row:
                continue
            row = [int(c.strip()) for c in row]
            if percepts:
                assert len(row) == len(percepts[0]), \
                       "rows must have the same length"
            percepts.append(row)
        return percepts
    finally:
        if f is not None:
            f.close()