# [Tutor] I've run into a jam on the exercise on file I/O

Mon Aug 1 22:47:56 CEST 2005

```>>> max_points = [25,25,50,25,100]
>>> assignments = ['hw ch 1','hw ch 2','quiz ','hw ch 3','test']
>>> students = {'#Max':max_points}
>>> students
{'#Max': [25, 25, 50, 25, 100]}

The problem is the key in students is a list not an integer.

On 8/1/05, Nathan Pinno <falcon3166 at hotmail.com> wrote:
>
> Hey all,
> I've seem to run into a jam while working on the exercise on file I/O.
> Here's the error:
> Filename to save: university.txt
> Traceback (most recent call last):
> File "D:\Python22\grades.py", line 99, in ?
> out_file.write(x+","+max_points[x]+"\n")
> TypeError: sequence index must be integer
>  And the code:
> max_points = [25,25,50,25,100]
> assignments = ['hw ch 1','hw ch 2','quiz ','hw ch 3','test']
> students = {'#Max':max_points}
> print "2. Remove student"
> print "9. Exit"
> print '\t',
> for i in range(len(assignments)):
> print assignments[1],'\t',
> print
> keys = students.keys()
> keys.sort()
> for x in keys:
> print x,'\t',
> print
>  def choice():
>  def school():
> return raw_input("Student: ")
> in_file = open(filename, "r")
> while 1:
> if in_line == "":
> break
> in_line = in_line[:-1]
> [students,max_points] = string.split(in_line,",")
> in_file.close()
> out_file = open(filename, "w")
> for x in students.keys():
> out_file.write(x+","+max_points[x]+"\n")
> out_file.close
> while 1:
> name = school()
> students[name] = [0]*len(max_points)
> print "Remove student"
> name = school()
> if students.has_key(name):
> del students[name]
> else:
> name = school()
> if students.has_key(name):
> print "Type in the number of the grade to record"
> print "Type in a 0 (zero) to exit"
> for i in range(len(assignments)):
> print i+1,' ',assignments[i],'\t',
> print
> which = 1234
> while which != -1:
> which = int(raw_input("Change which Grade: "))
> which = which-1
> if 0 <= which < len(grades):
> elif which != -1:
> else:
> filename = raw_input("Filename to load: ")
> filename = raw_input("Filename to save: ")
> break
> else:
> print "That's not a choice!"
> print "Goodbye."
> What's the problem, and how is it fixed?
>  Thanks,
> Nathan Pinno,
> Crew, Camrose McDonalds and owner/operator of Woffee
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20050801/d7d89f5d/attachment-0001.htm
```