1
首先解釋代碼會更容易解釋我的問題。如何取消字典初始化? python3.3
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
我明白了!謝謝,它工作;) –