I am using some python to do some variable name generation. For some reason I am only getting part of what I need.
import sys
import csv
params = csv.reader(open('params.csv'), delimiter=',', skipinitialspace=True)
flags_r = []
flags_w = []
numbers_r = []
numbers_w = []
station = ['AC1','DC1','DC1']
drive = ['','Fld','Arm']
for i in range(3):
for p in params:
try:
desc = p[1].split(' ')
desc = [part.capitalize() for part in desc]
desc = "".join(desc)
except IndexError, e:
print 'IndexError: %s' %(e,)
continue
print station[i],drive[i],p[0]
flags_r.append( 'mod%(station)s_%(drive)sP%(param)04dr_%(desc)s' % \
{ 'station' : station[i], 'drive' : drive[i], 'param': int(p[0]), 'desc':desc })
flags_w.append( 'mod%(station)s_%(drive)sP%(param)04dw_%(desc)s' % \
{ 'station' : station[i], 'drive' : drive[i], 'param': int(p[0]), 'desc':desc })
numbers_r.append( 'mod%(station)s_%(drive)sP%(param)04drn_%(desc)s' % \
{ 'station' : station[i], 'drive' : drive[i], 'param': int(p[0]), 'desc':desc })
numbers_w.append( 'mod%(station)s_%(drive)sP%(param)04dwn_%(desc)s' % \
{ 'station' : station[i], 'drive' : drive[i], 'param': int(p[0]), 'desc':desc })
print i
params.csv:
100, Speed Reference
101, Speed Feedback
for some reason it is outputting:
AC1 100
AC1 101
0
1
2
the reason for the try/except is to catch any blank rows or missing second fields in the csv file.
It appears that the inner loop only get executed on the first pass. The only reason I can see for this to happen would be the try/except as I have done an interactive example to test it.