1

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))?

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
e15purple
  • 29
  • 7

1 Answers1

0

You can use setattr:

self.button.clicked.connect(lambda _ : setattr(outside_object, 'username', self.username))
eyllanesc
  • 235,170
  • 19
  • 170
  • 241