I have several modules that have the same variable of same name in each. I am trying to write a function that can accept the name of the variable then sum its value over all of the modules. I need to do this because this is the case for several variables.
For example, I have modules moduleA, moduleB, and moduleC that each have within them var1, var2, and var3. I want to write a function that can accept the variable name, say var1 as an argument then calculate:
sum = moduleA.var1 + moduleB.var2 + moduleC.var3
and return the value of sum.
I tried several different ways but kept getting an error that the module does not contain that name. I have included my most recent attempt and the error below.
def sumYearly(name):
sum = january.name + february.name
return sum
where january and february are the names of modules and name is the variable I'm trying to use to pass in the variable that exists inside each module. This results in the following error message:
sum = january.name + february.name
AttributeError: 'module' object has no attribute 'name'
sumsumis not a keyword, just a builtin. Keywords can't be assigned to, likeNoneandif.