import csv


def read_csv_to_dict(filename):
    """Read in csv file and convert it into a list of dicts.

    This offers an easy import functionality of csv files with dataset metadata.

    Assumptions:
    1) The header rows contains the column names, named after Dataverse's
    dataset attribute standard naming convention.
    2) One row contains one dataset

    After the import, the created dict then can directly be used to set
    Dataset() attributes via ``Dataset.set(data)``.

    Parameters
    ----------
    filename : string
        Filename with full path.

    Returns
    -------
    list
        List with one dict per row (=dataset). The keys of the dicts are named
        after the columen names, which must be named after the Dataverse
        dataset metadata naming convention.

    """
    reader = csv.DictReader(open(filename), 'r')
    data = []
    for row in reader:
        data.append(dict(row))
    return data