[Tutor] accessing dynamically created py objects

Baker, Michael Michael.Baker@anchorgaming.com
Wed, 9 Jan 2002 10:10:44 -0800


i can make this function:

>>> def maker(n=10):
	for a in range(n):
		exec "N%s=0" % a
	print dir()


and then call it:
	
>>> maker(10)
['N0', 'N1', 'N2', 'N3', 'N4', 'N5', 'N6', 'N7', 'N8', 'N9', 'a', 'n']
>>> maker(20)
['N0', 'N1', 'N10', 'N11', 'N12', 'N13', 'N14', 'N15', 'N16', 'N17', 'N18',
'N19', 'N2', 'N3', 'N4', 'N5', 'N6', 'N7', 'N8', 'N9', 'a', 'n']
>>> 

i'm trying to use something like this to track ranges of a random number
generator. i need to access each object after it has been created to modify
its value. running another exec statement in the above example doesn't work
- exec "N%s=N%s+1" % n

i'd like to then return a list containing the aggregate values stored in
each object created when the function is run. 

how can i make this work??

thanks in advance
mb