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

Mat*_*cob 0 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
    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)
Run Code Online (Sandbox Code Playgroud)

这个想法是另一个类假设生成一个值的字典,该构造函数将其作为输入并搜索值以进行某些计算.但是,每当我运行我的程序(外部)时,我都会收到以下错误.

throughput = dict.get("output(kg/annum)",默认=无)#kg/annum

TypeError:get()不带关键字参数

有人可以解释这个错误意味着什么,以及我如何规避它?非常感谢你.

Kev*_*vin 6

throughput = dict.get("output(kg/annum)",default=None)  # kg/annum
Run Code Online (Sandbox Code Playgroud)

指定默认值时,请勿使用关键字"default".

throughput = dict.get("output(kg/annum)", None)  # kg/annum
Run Code Online (Sandbox Code Playgroud)

实际上,由于默认情况下默认值为None,因此您根本不必提供第二个参数.

throughput = dict.get("output(kg/annum)")  # kg/annum
Run Code Online (Sandbox Code Playgroud)