Creating alot of class instances?

kk maymunbeyin at
Sun Jul 5 14:59:01 EDT 2009


I am new to Python classes and trying to figure out this particular
issue here. I will need to create instances of a class. But at the
moment I do not know how many instances I will end up having, in every
case it might be different. Most of the documents I read makes this
simpl class-student analogy to explain python classes which is fine.
But in those examples the number and the names of the instances were
known and limited.

I will be querying some data and create class instances based on the
data I gather. But the problem as I mentioned is that I do not know
the names and the number of the end class instances. They will be
based on the content of the data. So how can I create class instances
within a loop and when the loop is done how can I figure out the list
of instances via class membership?  I can track the names by
introducing another list but I want to understand the class side of

The solution might be dead simple but I just cannot figure out at the

For example this is what I need in the simplest form

class myclass():
 def __init__(self,name):

for count,data in enumerate(some list):

print instances


More information about the Python-list mailing list