Skip to content

read_list_table

Syntax

read_list_table(list_table_name, "filename", key_col, val_col)

Parameters

list_table_name
The list-table to update
filename
The name of comma-separated file, surrounded by quotes. The filename may include the path to the file in addition to the name.
key_col
The index of the column containing keys (starting from 0)
val_col
The index of the column containing values

Description

Populates a list-table with key-value pairs from a CSV file.

Updates a provided list-table with a series of key-value pairs from the specified filename. The file must be a comma-separated-value file that contains the indicated columns. For each key-value pair read from the file, the value is updated or appended to the list associated with the key in list_table.

Empty lines in the file are ignored.

Lines with a non-numeric value in the first column are ignored.

The value associated with any key that appears in the key_col is replaced by the list of values for that key in the file. Other keys are not affected.

An error occurs if the file is not found, or if the column indices do not exist.

Examples

population.csv

key,       value
"[1,2,3]", "[4,5,6]" 
5, "[10,11,12]"
10, "[13,14,15]"

variables {
    shared table my_list_table
}

condition LOADING {
    meta_start_state = Start

    state Start {
        # populate table with key and value from .csv file
        read_table(my_list_table, "population.csv", 0, 1)

        wait()
        default()
    }
}

See Also