On Fri, Dec 23, 2011 at 6:42 PM, Alan Gauld <alan.ga...@btinternet.com> wrote: > On 23/12/11 10:01, lina wrote: > >> with open(filename,"r") as f: >> for line in f: >> parts = f.readline().strip() > > > Are you sure you want to do this? > You are already reading a line from the file in the for loop. > This will read the next line. So parts will comprise every second line in > the file. Is that what you want?
No. that's why I am so confusing now. why the results so un-expected. did not print the even line out (if the first line is odd line). > > > >> if len(parts) == 26: >> dist = parts.split()[1] >> print(dist) >> result[i].append(dist) >> print(result) >> >> $ cat A_mindist_1.xvg >> 4.640000e+05 3.169008e-01 >> 4.680000e+05 4.319328e-01 >> 4.720000e+05 5.126960e-01 >> >> >> $ cat A_mindist_2.xvg >> 4.640000e+05 5.237660e-01 >> 4.680000e+05 2.352828e-01 >> 4.720000e+05 2.280239e-01 >> >> >> I wish >> result[0] = >> 3.169008e-01 >> 4.319328e-01 >> 5.126960e-01 >> >> result[1] = >> 5.237660e-01 >> 2.352828e-01 >> 2.280239e-01 > > > This suggests you want each line so i'd expect your code to look more like > > > with open(filename,"r") as f: > for line in f: > result[i].append(line.strip().split()[1]) > > > -- > Alan G > Author of the Learn to Program web site > http://www.alan-g.me.uk/ > > > _______________________________________________ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor