通过首先解释代码来解释我的问题会更容易。你知道吗
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)
initialize_function
函数有一个参数instruction
。instruction
是一个字符串,相当于function_mapping
字典的一个键。
所以当我执行current_pipeline=function_mapping[instruction]
时,它应该只执行instruction
的值。实际上function_mapping
字典在寻找键instruction
之前就被初始化了,所以它一个接一个地执行所有的函数LOAD,STORE,MOVE,IADD,FADD。你知道吗
我能做什么?你知道吗
提前感谢:)
MFF公司
因为所有函数的参数都是相同的,所以应该可以:
说明:由于您实际上是在调用函数,因此您的字典值将在运行时进行计算。您希望将引用传递给它们,因为函数是python中的第一类对象,所以您可以这样做。你知道吗
相关问题 更多 >
编程相关推荐