# Beginner question: use function to read text file

Luke lhw1 at netspace_no_s_pa_m.net.au
Tue Jun 27 03:09:45 CEST 2006

I'm pretty stuck at the moment and wondering if anyone can spot the problem.
Trying to create a function that will read a text file into a list and
return that list.

I wrote the following function and saved it as 'fileloader.py'

infile=open(fname)
dates =[]
times=[]
open=[]
high=[]
low=[]
close=[]
vol=[]
count=0
for line in infile:
item=line.split()
dates.append(item[0])
times.append(item[1])
open.append(item[2])
high.append(item[3])
low.append(item[4])
close.append(item[5])
vol.append(item[6])
#print
dates[count],times[count],open[count],high[count],low[count],vol[count]
count=count+1

return dates,times,open,high,low,close

Then I executed the following script (merge contract v1.py):

filename='c:/Python24/test/testdata2.txt'

I then get the following error messages:

Traceback (most recent call last)
File "C:\Python24\test\merge contract v1.py", in line3, in?