On 20 March 2013 06:12, Arijit Ukil <[email protected]> wrote: > I am new to python. My intention is to read the file digi.txt and store in > separate arrays all the values of each columns. However, the following > program prints only the last value, i.e. 1350696500.0. > Please help to rectify this. > > f = open ("digi.txt", "r+") > > datafile = f.readlines() > > list_of_lists = datafile > for data in list_of_lists: > lstval = data.split (',') > timest = float(lstval[0]) > energy = float(lstval[1]) > > f.close() > print timest > A few questions to ask yourself.
Is 'f' a descriptive name, equivalent to your other variable names? What does your third line do, and do you think it's actually required? What implications would it cause if you removed it? How do you overcome those issues? What value is stored in 'timest' the first iteration of the loop, the second, the third? (Put a print statement in the loop to find out) Are you actually doing anything with 'energy'? Do you need to wait until after the loop to close your file? HTH, Bodsda _______________________________________________ Tutor maillist - [email protected] To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
