在编写程序的时候,代码报错为:
Exception has occurred: TypeError
Calculator.calculate_engine_power() missing 3 required positional arguments: 'self', 'engine_initial_rpm', and 'engine_target_rpm'
File "calc.py", line 76, in calculate_power_output instance = Calculator.calculate_engine_power() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "\calc_result.py", line 47, in create_instance acg_V_dc_corrected_1, acg_I_out_1, acg_P_out_1 = acg_instance_1.calculate_acg_power_output() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "\calc_result.py", line 190, in <module> params_obj.create_instance() TypeError: Calculator.calculate_engine_power() missing 3 required positional arguments: 'self', 'engine_initial_rpm', and 'engine_target_rpm'
主要问题
在同一个class中要调用不同def中的变量,不能采用简单的instance = ClassName(),然后再引用。
解决办法
首先,将需要调用的变量名作为返回量,其次,定义如下:
variable1, variable2, ..., variable n = self.defname(
self.params["param name"] #这里是在被引用定义中的那些个参量。
}