Problem with assign,

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 not assign to operator

I can not assign a int to the "transaction" class ... Let's assume that

from_key = a
 to_key = b
 SN = 123

I want to get the following result: ab123 = transaction(SN,from_key,to_key,True)

Manually (out of function), it works, but when I try to automate the function I get this error.

Update:

I need to give a name to a class (transaction) and determined that this name will be my from_key + to_key + SN , in my example it would be ab123 . The problem is that each time I make a transaction this name will change, and I created a function to perform this assing alone ( ab123 = transaction(...) ). How can I make this work?

    
asked by anonymous 03.09.2018 / 21:49

1 answer

0

You can create a dictionary and use the generated string as a key:

cache = dict()

def send(from_key, to_key, SN):
    if SN in from_key.parts:
        key = str(from_key) + str(to_key) + str(SN)
        cache[key] = transaction(SN, from_key, to_key, True)

To retrieve the result of transaction(...) just use:

print(cache['ab123'])  # ou qualquer que seja a chave
    
03.09.2018 / 22:14