I'm trying to generate variables automatically and put them in a csv file, to do so, I'm using the code bellow, which works fine:
#val is the number of points I want to generate and store them in a list:
val = 3
list_of_points = []
#Generate 3 points automatically:
g = globals()
for i in range(1, val+1):
g['p{0}'.format(i) ] = str('p{0}'.format(i))
list_of_points.append(g['p{0}'.format(i)])
My problem is that I want to put them inside the "for()" loop and also the dictionnary bellow it, I can't think of any way to do this, there is my code bellow:
writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
for (p1,p2,p3) in zip(list_p1,list_p2,list_p3):
writer.writerow({'p1': p1, 'p2': p2,'p3': p3})
Any idea how can I achieve this ? thanks.