When trying to connect a button press to the assignment of a variable, PyCharm refuses to accept the syntax, stating Can't assign to function call
with red syntax underlining.
Here is the following code:
self.button.clicked.connect(lambda : outside_object.username = self.username)
How can I assign a variable without calling something similar to a setter method such as self.button.clicked.connect(lambda: outside_object.assign_username(self.username))
?
You can use setattr
:
self.button.clicked.connect(lambda _ : setattr(outside_object, 'username', self.username))