I think you already have an idea about what to do. In particular, the idea touse a dictionary to store information using a key will make your code free ofexec
s. For example:
linesigs = {}for sig in stringsig: filename = 'SummerStc_{}_{}.txt'.format(stringcpu[1], sig) with open(filename, 'r') as filesig: linesigs[sig] = filesig.readlines()
Note that:
- You can iterate over the array directly to avoid using a counter
- It's useful to use the
with
statement to avoid forgetting about the closing files
Aside from this, a few more pieces of advices:
- If you absolutely need a counter, use
enumerate
in for loops to avoid keeping track of counters in the code - Use a template engine to generate the latex code like jinja2
I think your code needs a little bit of work, so feel free to apply some fixesand write a new question to get a new review on the improved code.