[Tutor] IndexError and appending to lists [Was: Re: Need Help on Assignment]

Tom Strickland tlinux at comcast.net
Wed Aug 24 03:31:59 CEST 2005


Danny,

Here's the working program.

Tom

*****************************************************************************************

#!/usr/bin/python2.4
input = open('/home/tom/Python/Input/SPY3.txt', 'r')
N=0
s = 'boo'
date =[]
T = [0,0,0,0,0,0]               #don't know why this is necessary
open = []
close = []
hi = []
lo = []
vol = []
while s:
    s = input.readline()
    if s == '':break
    s = s[:-2]
    T[N] = s.split(',')
    date.append(T[N][0])
    open.append(float(T[N][1]))
    hi.append(float(T[N][2]))
    lo.append(float(T[N][3]))
    close.append(float(T[N][4]))
    vol.append(float(T[N][5]))
    N+=1
print N
for i in range(N):
    T[i]
    print T[i]
    print date[i], open[i], hi[i], lo[i], close[i], vol[i]
print T[1][2], T[0][0]
z = (hi[2] +lo[2])/2.0
print z
   

***********************************************************************************************


Danny Yoo wrote:

>On Tue, 23 Aug 2005, Tom Strickland wrote:
>
>  
>
>>I changed the program in accordance with your advice and it now runs
>>perfectly!!!
>>    
>>
>
>Hi Tom,
>
>That's very good to hear; glad it's working now.
>
>If you don't mind, can you post up what you have now?  I left out some
>other suggestions to the program because they were more about style and
>Python idioms.  But now that you have a working program, it might be
>useful to cover those.
>
>Good luck!
>
>
>
>  
>




More information about the Tutor mailing list