0
class transaction:
...
def send(from_key, to_key, SN):
if SN in from_key.parts:
str(from_key)+str(to_key)+str(SN)=transaction(SN,from_key,to_key,True)
Syntaxerror: can’t assign to Operator
I can’t assign a int
to the "transaction" class...
Let’s assume that
from_key = a
to_key = b
SN = 123
I want to arrive at the following result:
ab123 = transaction(SN,from_key,to_key,True)
Manually (out of function), it works, but when I try to automate in the function I get this error.
Update:
I need to give a name to a class (transaction) and I’ve determined that name will be mine from_key + to_key + SN
, in my case would be ab123
.
The problem is that every time I go to perform a transaction that name will change, and I created a function to perform this assing alone (ab123 = transaction(...)
).
How can I make this work?
You can’t make a dynamic assignment this way. What you want is to dynamically generate the variable "ab123" according to the function parameters? And what will you do with this variable?
– Woss
I want to generate the variable according to what I entered in the send function, in my example would be
send(a,b,123)
. My problem is when I try to assign the variable to a class. Whyab123 = transaction(...)
works andstr(from_key)+str(to_key)+str(SN)=transaction(...)
nay?– João Victor Verona
Why do you need to do this? What will you do with the variable?
– Woss
It is not possible to assign a value to another value. In the case you are doing something like
"a" + "b" +"123" = transaction(...)
. What you can do and create a dictionary and insert these values using the generated string as key.– fernandosavio
how would I do it @fernandosavio?
– João Victor Verona
I will formulate an answer to facilitate
– fernandosavio
The variable must become a transaction, which in turn stores information from the same @Andersoncarloswoss ...
– João Victor Verona
And why can’t it be a normal variable, like
trans = transaction(...)
?– Woss
Because I would have to do it manually... I want the function, according to what I entered into it, to do the automatic assing. This function will perform other actions along with this...@Andersoncarloswoss
– João Victor Verona
That sounds like a XY problem. I advise you to consider the idea of [Edit] the question and explain by text what you are trying to do in the general context. It makes no sense to define a dynamic variable like this.
– Woss
I updated the post trying to explain better @Andersoncarloswoss
– João Victor Verona