Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/323.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何取消字典初始化?蟒蛇3.3_Python_Dictionary_Python 3.x - Fatal编程技术网

Python 如何取消字典初始化?蟒蛇3.3

Python 如何取消字典初始化?蟒蛇3.3,python,dictionary,python-3.x,Python,Dictionary,Python 3.x,通过首先解释代码,可以更容易地解释我的问题 def initialize_function(num,instruction,emplacement1,emplacement2,current_pipeline): function_mapping={ "LOAD" : LOAD(num,emplacement1,emplacement2,current_pipeline), "STORE" : STORE(num,emplacement1,emplacement2,cur

通过首先解释代码,可以更容易地解释我的问题

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_函数
函数有一个参数
指令
<代码>指令是一个字符串,相当于
函数映射
字典的一个键。 因此,当我执行
current\u pipeline=function\u mapping[instruction]
时,应该只执行
指令的值。但事实并非如此。实际上,
函数映射
字典在查找键
指令
之前已初始化,因此它会一个接一个地执行所有函数LOAD、STORE、MOVE、IADD、FADD

我能做什么

提前感谢:)


MFF

由于所有函数的参数都相同,因此应该可以:

def initialize_function(num,instruction,emplacement1,emplacement2,current_pipeline):
    function_mapping={
    "LOAD" : LOAD,
    "STORE" : STORE,
    "MOVE" : MOVE_IADD,
    "IADD" : MOVE_IADD,
    "FADD" : FADD
    }
    current_pipeline=function_mapping[instruction](num,emplacement1,emplacement2,current_pipeline)
    return(current_pipeline)

说明:由于您实际上正在调用函数,因此字典值将在运行时进行计算。您希望传递对它们的引用,因为函数是python中的第一类对象,所以您可以这样做。

因为所有函数的参数都是相同的,所以应该可以:

def initialize_function(num,instruction,emplacement1,emplacement2,current_pipeline):
    function_mapping={
    "LOAD" : LOAD,
    "STORE" : STORE,
    "MOVE" : MOVE_IADD,
    "IADD" : MOVE_IADD,
    "FADD" : FADD
    }
    current_pipeline=function_mapping[instruction](num,emplacement1,emplacement2,current_pipeline)
    return(current_pipeline)
说明:由于您实际上正在调用函数,因此字典值将在运行时进行计算。您希望传递对它们的引用,因为函数是python中的第一类对象,所以您可以这样做