[Tutor] Naming Instances of Classes
Daniel Yoo
dyoo@hkn.eecs.berkeley.edu
Sun, 8 Apr 2001 19:29:35 -0700 (PDT)
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.
Good luck to you.