I'm Python beginner. I'm trying to write a loop over a class and compare different results. Results are produced in a method called job. Then in each loop I want to run this method of the class. The last line of the code does not work. What is the possible solution?

Here is an example:

class test:
   def __init__(self,a)
       ...
   def job(self,x):
        ...

a = 5  # arbitrary numebr
instance_names = ['model_1', 'model_2', 'model_3']
for i, name in enumerate(instance_names):
    model_name = 'CC' + name
    model_job = model_name + '.job'
    vars()[model_name] = test(a)
    model_job(i)
Member Avatar for RudyM

Should 9 be for i, name in enumerate(class_names) ?

commented: yes, it is a typo, thanks for catching the typo +0
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.