Random Instance generation

Istvan Albert ialbert at mailblocks.com
Wed Sep 15 10:59:26 EDT 2004


Balaji wrote:

> Hello eveybody....
> 
> Suppose there is a class A:
> 
> I want to generate say 100 random instance of it...
> 
> How can I do that....
> 
> I want the instance name to be like a1, a2, a3...

Usually when you feel that you need to generate instances with
certain names you are on the wrong track in translating the
problem you need to solve into a program.

You can always store 100 instances in a list then iterate
over them.

If you need to identify individual instances by name, create
a data structure (the simplest is a dictionary)
that maps a name to an instance.

Istvan.



More information about the Python-list mailing list