[Tutor] Creating instances (group program revisited)

Blake Winton bwinton@tor.dhs.org
Mon, 26 Mar 2001 23:36:17 -0500


* Timothy Wilson <wilson@visi.com> [010326 23:07]:
> Notice that the Student __init__ method now "doesn't care" where the
> input string comes from. It could be from a file (via the loadFile
> method) or user input.

Always a good idea.  But it might be smart to allow people to create
a student with an empty string, and fill in the data values later.

> Here's the question. I think the loadFile method creates a Student
> instance for each line in the datafile, but I'm puzzles about how I'm
> going to reference those instances later. Essentially, this is why a
> previous incarnation had a Roster class which functioned as a
> container for all the Student objects. Would someone care to comment
> on this?

That would be where you want to stick them into something.
(note the lines I added...)

> def loadFile(datafile):
> 	f = open(datafile, 'r')
> 	nameList = f.readlines()
        class = []
> 	for i in nameList:
> 		Student(i)
                class.append( Student(i) )

Then you can pick people out of the class, and put them into groups.

Later,
Blake.
-- 
9:40pm up 52 days, 21:07, 2 users, load average: 0.02, 0.09, 0.07