How can I fix this syntax error when importing functions from another library

Stack Overflow Asked by David Weisskopf on January 1, 2022

I get a syntax error of SyntaxError: can't assign to function call located on the genwave function’s self.rp.set line. 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

def genwave(self, out_channel, waveform, voltage, offset):
    '''generates analog waveform out of the redpitaya from OUT 1'''
    self.rp.set(self, 0, voltage) = out_voltage
    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

3 Answers

You can't assign a value to a function. You probably meant to say: out_voltage = self.rp.set(self, 0, voltage)

Answered by Andrej on January 1, 2022

You are assigning a value to a function and that is not possible,

You can try anything like self.rp.set = out_voltage(self, 0, voltage) but not this self.rp.set(self, 0, voltage) = out_voltage

Answered by Danilo Toro on January 1, 2022

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. Calling the function usually returns value, this is contrary to how a function works.

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. BTW this error will occur for more function calls in genwave.

For example:

>>> int() = 0
  File "<stdin>", line 1
SyntaxError: can't assign to function call

Answered by Derek Eden on January 1, 2022

Add your own answers!

Related Questions

Main Thread Checker Error: Double to UILabel Fails Swift

1  Asked on December 13, 2021 by nisse82


Can’t create bitmap without Color space android

1  Asked on December 13, 2021 by iheb-404-notfound


fetch id who have register all adv

1  Asked on December 11, 2021 by user13974528


Is there a better way to write this snippet in python?

3  Asked on December 11, 2021 by paulo-sergio-schlogl


How to set if-else statement in a React function Return()?

4  Asked on December 11, 2021 by buffaurus


Check if the next item is 1 unit longer (Javascript)

3  Asked on December 11, 2021 by ekhi-arzac


adding onclick to an array of items

5  Asked on December 11, 2021 by helpmepiliizz


How to make sure only 1 thread is running? C++

1  Asked on December 11, 2021 by lordi1000


Ask a Question

Get help from others!

© 2023 All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP