在类中调用函数

时间:2016-06-09 11:05:53

标签: python

我试图将函数DataFrame集成到一个类中,但是我收到一个错误:

W_Kpower(scpi_comm)

你能帮我把这个功能整合到一个班级吗?我将来需要其他课程。我是初学者,所以我不了解我的代码的所有细节。

  keithley = rm.open_resource(instControl(inst_list))
NameError: global name 'self' is not defined

1 个答案:

答案 0 :(得分:3)

您在方法定义中缺少self

def W_KPower(scpi_comm):  # this should be def W_KPower(self, scpi_comm)
    return self.keithleyPower.write(":syst:loc")

我想在这里,你需要self.

def closeInst(self):
    W_KPower(":syst:loc")  # this should be self.W_KPower(":syst:loc")