Hi everyone. I have question and i hope someone will be pleased to help me. I am trying to write a python script which can extract data from a file (Iter.dat) and then put data in a tableau like the out.dat file. Here is what i wrote:
f = open('Iter.dat', 'r')
print('{:>4}{:>10}{:>8}{:>8}'.format('','canofica','lnvd','msd'))
data = [0, 0, 0]
prev = ""
for line in f:
a = line.split('/')
b = a[1].split(':')
c = b[0].split('.')
d = b[1].split(' ')
e = int(b[2])
if a[0] != prev:
prev = a[0]
print('{:>4}{:>10}{:>8}{:>8}'.format(a[0],data[0],data[1],data[2]))
if c[0] == "canofica":
data[0] = e
elif c[0] == "lnvd":
data[1] = e
elif c[0] == "msd":
data[2] = e
f.close()
And this is the result:
canofica lnvd msd
10_2 0 0 0
9_1 14 4 37
which is not quite i expected, which is not like the out.dat. So, can anyone help me please, where did i go wrong? Thanks in advance.