It will be easier to explain my problem by explaining the code at first.
def initialize_function(num,instruction,emplacement1,emplacement2,current_pipeline):
function_mapping={
"LOAD" : LOAD(num,emplacement1,emplacement2,current_pipeline),
"STORE" : STORE(num,emplacement1,emplacement2,current_pipeline),
"MOVE" : MOVE_IADD(num,emplacement1,emplacement2,current_pipeline),
"IADD" : MOVE_IADD(num,emplacement1,emplacement2,current_pipeline),
"FADD" : FADD(num,emplacement1,emplacement2,current_pipeline)
}
current_pipeline=function_mapping[instruction]
return(current_pipeline)
The initialize_function function has an argument instruction. instruction is a string equivalent to one of the keys of the function_mapping dictionnary.
So when I do current_pipeline=function_mapping[instruction] it is supposed to execute only the value of the instruction. But it doesn’t. Actually the function_mapping dictionnary is initialized before it looks for the key instruction so it executes one after the other all the functions LOAD,STORE,MOVE,IADD,FADD.
What can I do ?
Thank you in advance 🙂
MFF
Since the arguments to all of your functions are the same this should work:
Explanation: Your dictionary values will evaluated at runtime since you are actually calling the functions. You want to pass a reference to them instead and since functions are first class objects in python, you can do just that.