I'm trying to create a package with a module with a class that receives arguments and then selects a method within the class based on one of the arguments
import calcs.myModule as module
arg1 = 'state' # this argument is used to determine which calculation to run
arg2 = 5 # example
myObject = module.classCall(arg1, arg2)
results = myObject.calculate()
print(results)
Names have been changed for readability The module looks like this
class classCall(object):
def __init__(self, arg1, arg2):
self.arg1 = arg1
self.arg2 = arg2
def state1(self):
# calculations preformed here
return results
def calculate(self):
if self.arg1 == "state1"
results = state1(self)
But I'm receiving an error still
results = state1(self)
NameError: name 'state1' is not defined
I thought this should work. Why isn't it and what should I do?