ValueError调用具有多个参数的函数时Python中的错误“太多值无法解包(预期为2)”

2024-09-29 19:34:37 发布

您现在位置:Python中文网/ 问答频道 /正文

我有两个Python文件,在第一个文件中,我从第二个文件调用了一个函数。然而,我总是得到错误“ValueError:太多的值无法解包(预期为2)”,我不知道为什么会得到它。第二个文件中的函数接受16个参数并返回16个参数。这16个返回的参数被分配给第一个文件中的16个变量。但我每次都会犯这个错误。你们有人知道问题出在哪里吗

在这里,您可以看到第一个文件中函数调用的调用:

    self.action_heatCoefficientSpaceHeating, self.action_heatCoefficientDHW, self.action_chargingPowerEV, self.state_temperatureBufferStorage, 
    self.state_usableVolumeDHWTank, self.state_SOCOfTheEV, self.help_countNumberOfStartHeatPump_HeatingBufferStorage_Indiviual, self.help_countNumberOfStartHeatPump_HeatingDHW_Indiviual, 
    self.help_countNumberOfStartHeatPump_Heating_Combined , self.helpCounterNumberOfRunningSlots_SpaceHeating , self.helpCounterNumberOfRunningSlots_DHW , 
    self.helpCounterNumberOfRunningSlots_Combined , self.helpCounterNumberOfStandBySlots_SpaceHeating , self.helpCounterNumberOfStandBySlots_DHW , 
    self.helpCounterNumberOfStandBySlots_Combined, self.helpCurrentPeakLoad = ICSimulation.simulateTimeSlot_WithAddtionalControler_BT1 (self.action_heatCoefficientSpaceHeating, self.action_heatCoefficientDHW, self.action_chargingPowerEV, self.help_statePreviousTimeSlot_temperatureBufferStorage,
                                         self.help_statePreviousTimeSlot_usableVolumeDHWTank, self.help_statePreviousTimeSlot_SOCOfTheEV, self.help_countNumberOfStartHeatPump_HeatingBufferStorage_Indiviual, 
                                         self.help_countNumberOfStartHeatPump_HeatingDHW_Indiviual, self.help_countNumberOfStartHeatPump_Heating_Combined , self.helpCounterNumberOfRunningSlots_SpaceHeating , self.helpCounterNumberOfRunningSlots_DHW ,
                                         self.helpCounterNumberOfRunningSlots_Combined , self.helpCounterNumberOfStandBySlots_SpaceHeating , self.helpCounterNumberOfStandBySlots_DHW , self.helpCounterNumberOfStandBySlots_Combined, self.helpCurrentPeakLoad)

在这里,您可以看到第二个文件“ICSimulation”中的函数“simulateTimeSlot_with AddationalController_BT1”:

def simulateTimeSlot_WithAddtionalControler_BT1 (action_SpaceHeating, action_DHWHeating, action_EVCharging, state_BufferStorageTemperatureLastTimeSlot,
                                                 state_usableVolumeDHWLastTimeSlot, state_SOCofEVLastTimeSlot, helpCountNumberOfStartsIndividual_SpaceHeating, 
                                                 helpCountNumberOfStartsIndividual_DHW, helpCountNumberOfStarts_Combined , helpCounterNumberOfRunningSlots_SpaceHeating , helpCounterNumberOfRunningSlots_DHW ,
                                                 helpCounterNumberOfRunningSlots_Combined , helpCounterNumberOfStandBySlots_SpaceHeating , helpCounterNumberOfStandBySlots_DHW ,
                                                 helpCounterNumberOfStandBySlots_Combined, helpCurrentPeakLoad ):

    
    state_BufferStorageTemperatureCurrent =-1
    state_usableVolumeDHWCurrent = -1
    state_SOCofEVCurrent = -1
    action_SpaceHeating_corrected = -1
    action_DHWHeating_corrected = -1
    action_EVCharging_corrected = -1
    
    


    return action_SpaceHeating_corrected, action_DHWHeating_corrected, action_EVCharging_corrected, state_BufferStorageTemperatureCurrent, 
    state_usableVolumeDHWCurrent, state_SOCofEVCurrent, helpCountNumberOfStartsIndividual_SpaceHeating, helpCountNumberOfStartsIndividual_DHW, 
    helpCountNumberOfStarts_Combined , helpCounterNumberOfRunningSlots_SpaceHeating , helpCounterNumberOfRunningSlots_DHW , 
    helpCounterNumberOfRunningSlots_Combined , helpCounterNumberOfStandBySlots_SpaceHeating , helpCounterNumberOfStandBySlots_DHW , 
    helpCounterNumberOfStandBySlots_Combined, helpCurrentPeakLoad 

真正让我困惑的是,为什么它说应该是“2”?该函数接受16个参数并返回16个参数。我完全不知道为什么预期只有2个


Tags: 文件函数self参数helpactionstatecombined

热门问题