定义的方法没有在类中定义

时间:2017-10-24 01:44:15

标签: python

我正在尝试创建一个包含模块的包,该模块具有接收参数的类,然后根据其中一个参数选择类中的方法

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)

为了便于阅读,名称已被更改 该模块看起来像这样

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)

但我仍然收到错误

    results = state1(self)
NameError: name 'state1' is not defined

我认为这应该有效。为什么不是,我该怎么办?

0 个答案:

没有答案
相关问题