AnswerBun.com

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

    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

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

How to import util module in Node.js?

1  Asked on October 23, 2020 by lld

     

React.js search filtration on the array of objects

2  Asked on October 21, 2020 by ven-nilson

   

C# and the FileSystemWatcher

1  Asked on October 18, 2020 by thorsten-schroeer

       

C++ enum class with constructor

1  Asked on October 17, 2020 by cry0genic

   

Recharts ReferenceLine between data points

1  Asked on October 15, 2020 by philipp

   

Transform Issue With Bootstrap Card

3  Asked on October 15, 2020 by natalia-davydova

         

Ask a Question

Get help from others!

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