我得到了位于genwave函数的self.rp.set行上的SyntaxError: can't assign to function call的语法错误。我怎样才能摆脱这个错误?
import time
import rp
import numpy as np
import pyrpl
class PID:
"""PID Controller"""
def __init__(self, P=0.2, I=0.0, D=0.0, current_time=None):
self.Kp = P
self.Ki = I
self.Kd = D
self.sample_time = 0.00
self.current_time = current_time if current_time is not None else time.time()
self.last_time = self.current_time
self.targetT = targetT
self.clear()
def genwave(self, out_channel, waveform, voltage, offset):
'''generates analog waveform out of the redpitaya from OUT 1'''
self.rp.analog()
self.rp.set(self, 0, voltage) = out_voltage
self.rp.funct_gen()
self.rp.set_waveform(self, 1, waveform) = wave_output
self.rp.set_amplitude(self, 1, voltage) = wave_amplitude
self.rp.set_offset(self,1, offset) = voltage_offset发布于 2020-07-25 01:10:20
错误在这里说明了一切:
SyntaxError: can't assign to function callself.rp.set正在被调用,然后被赋值为out_voltage。调用函数通常返回值,这与函数的工作方式相反。
我不确定self.rp.set实际上做什么或者返回什么,或者out_voltage是什么,但是看起来这个表达式应该在等号上翻转,但是这个函数永远不会对out_voltage做任何事情,所以很难说出来。顺便说一下,在genwave中进行更多的函数调用时,会出现此错误。
例如:
>>> int() = 0
File "<stdin>", line 1
SyntaxError: can't assign to function call发布于 2020-07-25 01:17:16
您正在为函数赋值,但这是不可能的,
您可以尝试任何类似self.rp.set = out_voltage(self, 0, voltage)的命令,但不能使用此self.rp.set(self, 0, voltage) = out_voltage
发布于 2020-07-25 01:18:11
你不能给一个函数赋值。你可能想说:out_voltage = self.rp.set(self, 0, voltage)
https://stackoverflow.com/questions/63078239
复制相似问题