Naming class instances in real time

Steve Holden sholden at holdenweb.com
Mon Aug 12 23:25:22 EDT 2002


"Neil MacMillan" <neil at maxwell.bc.ca> wrote ...
> On Mon, 12 Aug 2002 19:46:07 +0000, Fredrik Lundh wrote:
>
> *snip*
> >> 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.
>

In that case you are to be congratulated. Pay no attention to the effbot's
brusqueness, its advice is usually sound(er than mine). I suspect all the
implementation work on regular expressions has soured its outlook a little.
Of course, even if you *weren't* aware of what everyone else does, that's no
reason not to do it yourself if it works.

It's a sound general rule that if you appear to need to generate variable
names on the fly your approach may bear re-thinking.

regards
-----------------------------------------------------------------------
Steve Holden                                 http://www.holdenweb.com/
Python Web Programming                http://pydish.holdenweb.com/pwp/
-----------------------------------------------------------------------








More information about the Python-list mailing list