Jinja2 and CSV

CVS can be use as a Dictionary :
1 Line = Keys
2 Line = Values
etc….

Each Keys/Values ( Columns ) are separated by a ‘ , ‘
If more then one value is added for one key then it is done by spacing : 10.10.10.1 10.10.10.2 10.10.10.3

To open and read an CSV file :
import jinja2
import csv

var_file = “file.CSV”
with open(var_file) as f:
….var_csv = csv.DictReader(f)

For when there is more then one value :
for dict_vars in var_csv:
…. network_routes = dict_vars[‘network_routes’]
….┬ánetwork_routes =network_routes.split()
….dict_vars[‘network_routes’] =┬ánetwork_routes

 

Reference :
Python for Network Engineers

 

 

Leave a Comment