0

I have a file called Model.py that contains the code

class ModelCalibrator():
    def __init__(self):
        self.file1 = 'Mortality_Population.txt'
        self.file2 = 'Deaths_1x1_adj.txt'
        self.MaxAge = 101
        self.MinAge = 18
        self.basisAges = np.array([18, 50, 100])[np.newaxis]
        self.mortalityData = PopulationData()
        self.deathRateData = DeathRateData()
        (self.age, self.phis) = computeBasisFunctions(ModelCalibrator)

def computeBasisFunctions(mc):
    MaxAge = mc.MaxAge
    MinAge = mc.MinAge
    age = np.arange(MinAge, MaxAge)[np.newaxis]

    basisAges = mc.basisAges
#calculations
...
return (age, phis)

In a separate test.py file I am running nosetests using the code

def testMC():
    data = ModelCalibrator()
    Phi = data.phis()
    assert_equal(Phi[0], 1)

This keeps telling me that I have an attributeerror: type object 'ModelCalibrator' has no attributes 'MaxAge'. Can anyone tell me where I am going wrong please?

1 Answer 1

1

On this line, you are passing in the class instead of the object. Try replacing ModelCalibrator with self. The class is only a template for the object. self represents the current object with all of the properties set.

(self.age, self.phis) = computeBasisFunctions(self)

Alternatively, if you want these to be accessible without an object, you could set MaxAge and MinAge as class variables by moving them outside of the __init__ function, but inside the class as shown here.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.