[Tutor] Naming Instances of Classes

Rick Pasotto rick@niof.net
Sun, 8 Apr 2001 23:20:07 -0400


On Sun, Apr 08, 2001 at 07:29:35PM -0700, Daniel Yoo wrote:
> On Sun, 8 Apr 2001, Rick Pasotto wrote:
> 
> > On Sun, Apr 08, 2001 at 05:28:31PM -0700, Britt Green wrote:
> > > I have a little problem thats been vexing me for the past week. If
> > > I have a class, how do you name the instances of that class? In
> > > all the code I've seen its always been hardcoded like this:
> > > 
> > > class Employee: pass
> > > 
> > > john = Employee()
> > > 
> > > Instead of hardcoding it, how can I make my program automatically
> > > give a unique name or number to a new class?
> > 
> > How are you going to refer to it if you don't give it a name?
> 
> You can put it into a Python list --- the list itself would have a
> name, but the contents could be indexed by number:
> 
>     employees = []
>     for i in range(10):
>         employees.append(Employee())
> 
> would create a list of 10 employees.  I'm not sure if this is what you
> want, though.

Precisely. The names would then be employees[0], employees[1], etc.

What the original poster was asking for doesn't make any sense.

-- 
"Moderation in temper is always a virtue; but moderation in
 principle is always a vice."
		-- Thomas Paine, _The Rights of Man_ (1791)
		   Rick Pasotto email: rickp@telocity.com