Naming class instances in real time
peter at engcorp.com
Tue Aug 13 06:11:03 CEST 2002
Neil MacMillan wrote:
> On Mon, 12 Aug 2002 19:46:07 +0000, Fredrik Lundh wrote:
> >> Can I then have a limited but unknown number of instances of that class
> >> in a running program named:
> >> >>>person0 = People()
> >> >>>person1 = People()
> >> >>>person2 = People()
> > why not do like everyone else, and put your instances in a list?
> Because I've never been formally taught a programming language
> (discounting bits of Pascal in high school); I figured out the basics of
> how OOP works yesterday; and therefore I don't *know* what everybody else
> does. Hence, the question. Thank you for telling me, though, I
> appreciate it.
The key in asking about this kind of thing is to make sure you
identify your _requirements_, not just the implementation you believe
you need. You did a good job with "limited but unknown number of
instances of that class in a running program" above.
The first part of the question, "is there a way ... to name class
instances without hardcoding the names?" is the kind of thing to
avoid, since you're asking how to implement the solution you think
you want. Still, examples of what you think you want are always
helpful in providing appropriate answers, too.
Luckily you gave both types of input. The difficulty is in knowing
when you don't know something. :)
More information about the Python-list