[Tutor] Something I don't understand
Eric Brunson
brunson at brunson.com
Tue Dec 18 21:48:56 CET 2007
Jim Morcombe wrote:
> Below, "student_seats" is a list of the class "student".
>
> Why does this code set every student.row to zero when there is only one
> student in the list with row > 5?
> It still sets them all to zero if I change the test to ">200" when there are
> no student.rows > 200.
> But if I change the test to "<1" then nothing gets set to zero.
>
>
> Jim
>
>
> class student:
> def __init__ (self, name, row, column):
> self.name = name
> self.row = row
> self.column = column
>
>
>
> for student in student_seats:
>
Try making your index variable (student) something that is not the same
name as the class.
> print student.name, "row = ", student.row, "column = ",
> student.column
> if student.row > 5:
> student.row = 0
> print student.name, "row = ", student.row, "column = ",
> student.column
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
More information about the Tutor
mailing list