[Tutor] Help required

Mitya Sirenef msirenef at lightbird.net
Thu Apr 4 15:26:47 CEST 2013


On 03/20/2013 02:12 AM, Arijit Ukil 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
> fordata inlist_of_lists:
>     lstval = data.split (/','/)
>     timest = float(lstval[0])
>     energy = float(lstval[1])
>
> f.close()
> printtimest
>
> Regards,
> Arijit Ukil


You would want to create an empty list and then
append values to it inside the loop. E.g. lst=[]; lst.append(val)

  -m

-- 
Lark's Tongue Guide to Python: http://lightbird.net/larks/



More information about the Tutor mailing list