open_csv¶
Syntax¶
Parameters¶
out_filename- The filename of the CSV to be produced, with its extension, surrounded by quotes.
col_1,...,col_n- A comma-separate list of header names (in quotes!) to place at the start of the file. Each header name must be a non-empty string of alphanumeric and underscore characters.
Description¶
Opens an output CSV file, allowing for print_csv to write values to it.
It is a run-time error to call open_csv() more than once on the same file.
Examples¶
The following prints the value of the likes_baseball agent variable for every
ordinary agent ID defined in a file called agents.txt to out.txt.
agents.txt
main.fred
simulation {
locations = none
default_model = none
start_date = 2020-Jan-01
end_date = 2020-Jan-01
}
variables {
agent numeric likes_baseball
}
condition TEST {
start_state = Agent_Start
meta_start_state = Meta_Start
state Meta_Start {
read_agent_file("agents.txt")
open_csv("out.txt","id","likes_baseball")
wait()
default()
}
state Agent_Start {
print_csv("out.txt",id,likes_baseball)
wait()
default()
}
}