[Tutor] Creating multiple instance names

Bob Gailer ramrom@earthling.net
Fri Mar 14 11:36:01 2003


--=======14D47B1C=======
Content-Type: text/plain; x-avg-checked=avg-ok-48D13BA; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 8bit

At 04:12 PM 3/14/2003 +0000, Lugo Teehalt wrote:
>Is it possible to use 'for' or 'while' or the like to create
>arbitrarilly many named class instances? Tried to do somethinglike:
>
>for i in ['a', 'b', 'c', 'd']:
>i = Counter() #Counter being a class
>print a.y, b.y, c.y, d.y # y is a thing from the class e.g. self.y = 0.
>
>(i.e. I'm trying to create four instances named a, b, c and d.)
>[snip]

for i in ['a', 'b', 'c', 'd']:
   exec(i + ' = Counter()')

--OR--

for i in ['a', 'b', 'c', 'd']:
   globals[i] = Counter()

(you can also say for i in 'abcd':)

Bob Gailer
mailto:ramrom@earthling.net
303 442 2625

--=======14D47B1C=======
Content-Type: text/plain; charset=us-ascii; x-avg=cert; x-avg-checked=avg-ok-48D13BA
Content-Disposition: inline


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.459 / Virus Database: 258 - Release Date: 2/25/2003

--=======14D47B1C=======--