Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/363.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构造函数的输入_Python_Dictionary - Fatal编程技术网

从字典中查找某些值作为python构造函数的输入

从字典中查找某些值作为python构造函数的输入,python,dictionary,Python,Dictionary,因此,我有以下代码: # constructor def __init__(self, dict): # Inputs harvesting_time = 16 # hours recovery_rate = 90 # % unit_throughput = 93.63 # kg/annum/unit cost_per_unit = 275000 # $ electricity = 0.0000331689825 # kWh/kg/unit

因此,我有以下代码:

# constructor
def __init__(self, dict):

    # Inputs
    harvesting_time = 16 # hours
    recovery_rate = 90 # %
    unit_throughput = 93.63 # kg/annum/unit
    cost_per_unit = 275000 # $
    electricity = 0.0000331689825  # kWh/kg/unit
    energy_cost = 10.41  # cent/kWh
    labor_cost = 1777000  # $/annum
    concentration = 100 # g/L

    throughput = dict.get("output(kg/annum)",default=None)  # kg/annum
    carbon = dict.get("carbon",default=None)
    nitrogen = dict.get("nitrogen",default=None)
    carbohydrates = dict.get("carbohydrates",default=None)
    proteins = dict.get("proteins",default=None)
    lipids = dict.get("lipids",default=None)
其思想是假设另一个类生成一个值字典,该构造函数将其作为输入,并搜索这些值以进行某些计算。然而,每当我运行我的程序(外部),我得到以下错误

吞吐量=dict.get(“产量(千克/年)”,默认值=无)#千克/年

TypeError:get()不接受关键字参数

有人能解释一下这个错误是什么意思,我怎样才能避免它?多谢各位

throughput = dict.get("output(kg/annum)",default=None)  # kg/annum
指定默认值时不要使用关键字“default”

throughput = dict.get("output(kg/annum)", None)  # kg/annum
实际上,由于默认值是None,所以您根本不需要提供第二个参数

throughput = dict.get("output(kg/annum)")  # kg/annum
指定默认值时不要使用关键字“default”

throughput = dict.get("output(kg/annum)", None)  # kg/annum
实际上,由于默认值是None,所以您根本不需要提供第二个参数

throughput = dict.get("output(kg/annum)")  # kg/annum

只需删除所有
dict.get
中的
default=None
,您将获得完全相同的结果只需删除所有
dict.get
中的
default=None
,您将获得完全相同的结果