Re: Creating alot of class instances?
- From: Rickard Lindberg <ricli85@xxxxxxxxx>
- Date: Sun, 5 Jul 2009 22:38:50 +0200
Thank you soo much for speedy and in detailed help. Your replies
really cleared out most of the cloud for me. I have one last issue to
resolve which is something I did not articulate properly, I realize
now. The last issue is actually automatically naming the instances.
The reason I was using the "instance_count" is for enumerating the
actual name of an instance.
For example lets say I have
class MyMaterials:
and my instances might need to look like
material_01
material_02
or
light_01
light_02
or
Mesh_01
Mesh_02 etc
If you do not know how many instances you are going to create from the
beginning, there is no way for you to know which of the instances you mentioned
above will get created. So having names for all of the instances will not help
you since you will never know what names are "safe" to use.
On the other hand, if you have all instances in a list, you can refer to them
by index and you know exactly how many of them you have.
If you would like to get instances by some name you gave to them, maybe
something like this will work:
def get_instance(name):
for instance in instance_list:
if instance.name == name:
return instance
return None
Note that this might very well return None if no instance with that particular
name was found.
--
Rickard Lindberg
.
- References:
- Creating alot of class instances?
- From: kk
- Re: Creating alot of class instances?
- From: Tim Chase
- Re: Creating alot of class instances?
- From: kk
- Creating alot of class instances?
- Prev by Date: Earning
- Next by Date: memoization module?
- Previous by thread: Re: Creating alot of class instances?
- Next by thread: Re: Creating alot of class instances?
- Index(es):
Relevant Pages
|