In the following code I wanted to skip the content (a lot of not usable content in files ex1.idl
and ex2.idl
) and get to the data with which to work. This data begins at the 905th value on each line of each file. Snippets of the files are:
ex1.idl
0.11158E-13 0.11195E-13 0.11233E-13 ...
ex2.idl
0.11010E-13 0.11070E-13 0.11117E-13 ...
I can successfully skip the unneeded values. I can also do some splitting, slicing and calculating. But when I combine the two, the code does not seem to work. The following is the combined code that I have:
with open('ex1.idl') as f1, open('ex2.idl') as f2:
with open('ex3.txt', 'w') as f3:
a = 905 #the first part
f1 = f1.readlines(905:)[a-1:] #the first part
f2 = f2.readlines(905:)[a-1:] #the first part
f1 = map(float, f1.read().strip().split()) #the second part
f2 = map(float, f2.read().strip().split()) #the second part
for result in map(lambda v: v[0]/v[1], zip(f1, f2)): #the second part
f3.write(str(result)+"\n") #the second part
This is the code where I just read the data and do the splitting and calculating alone. This works:
with open('primer1.idl') as f1, open('primer2.idl') as f2:
with open('primer3.txt', 'w') as f3:
f1 = map(float, f1.read().strip().split())
f2 = map(float, f2.read().strip().split())
for result in map(lambda v: v[0]/v[1], zip(f1, f2)):
f3.write(str(result)+"\n")
So I only want to add that the program starts the reading and computing at line 905.
Thanks in advance for the answer.