changed variable interpolation to be useable in connection with dictionary definitions for formulas. Slightly less efficient but now much more powerful...

This commit is contained in:
Tias Maiti 2014-05-02 19:56:56 +00:00
parent a5d5608063
commit 0885ea8023
1 changed files with 5 additions and 5 deletions

View File

@ -89,8 +89,8 @@ for file in files:
for label,formula in zip(options.labels,options.formulas): for label,formula in zip(options.labels,options.formulas):
interpolator = [] interpolator = []
for position,column in enumerate(set(re.findall(r'#(.+?)#',formula))): # loop over unique set of column labels in formula for column in re.findall(r'#(.+?)#',formula): # loop over column labels in formula
formula = formula.replace('#'+column+'#','{%i}'%position) formula = formula.replace('#'+column+'#','%f')
if column in specials: if column in specials:
interpolator += ['specials["%s"]'%column] interpolator += ['specials["%s"]'%column]
elif column.isdigit(): elif column.isdigit():
@ -107,7 +107,7 @@ for file in files:
brokenFormula[label] = True brokenFormula[label] = True
if label not in brokenFormula: if label not in brokenFormula:
evaluator[label] = "'" + formula + "'.format(" + ','.join(interpolator) + ")" evaluator[label] = "'" + formula + "'%(" + ','.join(interpolator) + ")"
# ------------------------------------------ calculate one result to get length of labels ------ # ------------------------------------------ calculate one result to get length of labels ------
table.data_read() table.data_read()