Instantatating an array of objects

Hello Everyone !
Actually I was instantating a array of objects like that :

    covergroup_names = [x for x in dir(coverage_points) if isclass(getattr(coverage_points, x))]
    
    covergroup_insts = [globals()[groupname](uut) for groupname in covergroup_names]

And now the thing is that I added a method within the class called instant that instantiates if it’s not instatiated yet.

So how can I changed the second line in order to call this method for each groupname. (Instead of having [globals()groupname] how can I access this method for each element

By Walid via Discussions on Python.org at 12Jul2022 07:34:

Hello Everyone !
Actually I was instantating a array of objects like that :

   covergroup_names = [x for x in dir(coverage_points) if isclass(getattr(coverage_points, x))]

   covergroup_insts = [globals()[groupname](uut) for groupname in covergroup_names]

Ok, so you’re inspecting coverage_points which is maybe a module?

And now the thing is that I added a method within the class called instant that instantiates if it’s not instatiated yet.

I’m not sure I understand this sentence. I feel like there’s context
here you’ve not mentioned.

So how can I changed the second line in order to call this method for
each groupname. (Instead of having [globals()groupname] how can
I access this method for each element

Well, it seems to me that globals()[groupname] is the class from which
you want an instance. So, if each of these classes has an instant
method to return a new instance, what’s wrong with
globals()[groupname].instant() ?

Cheers,
Cameron Simpson cs@cskk.id.au

Yes perfect I was just looking for this, and it works