Random Instance generation

Paul McNett p at ulmcnett.com
Tue Sep 14 16:58:55 EDT 2004


Balaji writes:

> Suppose there is a class A:
> I want to generate say 100 random instance of it...

Define "random instance".


> How can I do that....
> I want the instance name to be like a1, a2, a3...

If you just want to make 100 instances of a class, try something 
like:

class A(object): pass

for count in range(100):
	exec "a%s = A()" % count

That is hardly random, though.

-- 
Paul McNett
Independent Software Consultant
http://www.paulmcnett.com



More information about the Python-list mailing list