Python运行时错误(SyntaxErrorException):必须在此处指定默认值

Python Runtime error (SyntaxErrorException): default value must be specified here

我有以下代码

class PV_gen(object):

def __init__(self,_name,surfacename_,performance_type = "PhotovoltaicPerformance:Simple",performance_name,_integrationmode,No_parallel,No_series):

    self.name = _name
    self.surfacename = surfacename_
    self.performancetype = performance_type
    self.performancename =  performance_name
    self.integrationmode = _integrationmode
    self.NOparallel = No_parallel
    self.NOseries = No_series

    self.PV_performance()

def PV_performance(self,_namenamePVperform = "test",SA_solarcells = 0.5 ,cell_efficiencyinputmode = "Fixed",cell_n = 0.12, schedule_ = "always on"):

    self.name = _namenamePVperform
    self.surfaceareacells = SA_solarcells
    self.cellefficiencyinputmode = cell_efficiencyinputmode
    self.efficiency = cell_n
    self.schedule = schedule_

每当我尝试在 init 中指定默认值时,我都会收到这样的运行时错误

运行时错误(SyntaxErrorException):必须在此处指定默认值 文件“”,第 5 行 def init(self,name,surfacename,performance_type = "PhotovoltaicPerformance:Simple",performance_name,_integrationmode,No_parallel,No_series):

语法错误:必须在此处指定默认值

我无法弄清楚这里出了什么问题我想指定 performance_type 具有字符串 "PhotovoltaicPerformance:Simple" 的默认值。有人可以给我一些指示吗?

必需的参数必须列在默认参数之前。将具有默认值的参数移动到参数列表的末尾。

你的 default argument 必须 follow non-default argument。所以参数performance_type必须在最后声明。

def __init__(self,_name,surfacename_,performance_type = "PhotovoYou ltaicPerformance:Simple",performance_name,_integrationmode,No_parallel,No_series):

应采用以下形式:

def __init__(self,_name,surfacename_,performance_name,_integrationmode,No_parallel,No_series,performance_type = "PhotovoltaicPerformance:Simple"):

类似问题here