[英]How can I fix this syntax error when importing functions from another library
I get a syntax error of SyntaxError: can't assign to function call
located on the genwave function's self.rp.set line.我收到语法错误
SyntaxError: can't assign to function call
位于 genwave 函数的 self.rp.set 行。 How can I get rid of this error?我怎样才能摆脱这个错误?
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
The error says it all here:错误在这里说明了一切:
SyntaxError: can't assign to function call
self.rp.set
is being called and then being assigned a value of out_voltage
. self.rp.set
被调用,然后被分配一个值out_voltage
。 Calling the function usually returns value, this is contrary to how a function works.调用 function 通常返回值,这与 function 的工作方式相反。
I'm not sure what self.rp.set
actually does or returns, or what out_voltage
is but it almost looks like the expression should be flipped on the equal sign, but then the function never does anything with out_voltage
so kind of hard to say.我不确定
self.rp.set
实际做什么或返回什么,或者out_voltage
是什么,但看起来表达式应该在等号上翻转,但是 function 从来没有对out_voltage
做任何事情,所以很难说. BTW this error will occur for more function calls in genwave
.顺便说一句,对于 genwave 中的更多
genwave
调用,将发生此错误。
For example:例如:
>>> int() = 0
File "<stdin>", line 1
SyntaxError: can't assign to function call
You are assigning a value to a function and that is not possible,您正在为 function 分配一个值,这是不可能的,
You can try anything like self.rp.set = out_voltage(self, 0, voltage)
but not this self.rp.set(self, 0, voltage) = out_voltage
您可以尝试任何类似
self.rp.set = out_voltage(self, 0, voltage)
但不是这个self.rp.set(self, 0, voltage) = out_voltage
You can't assign a value to a function.您不能为 function 分配值。 You probably meant to say:
out_voltage = self.rp.set(self, 0, voltage)
你可能是想说:
out_voltage = self.rp.set(self, 0, voltage)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.