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

时间:2015-03-29 05:33:34

标签: python syntax-error default-value

我有以下代码

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):

SyntaxError:必须在此处指定默认值

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

2 个答案:

答案 0 :(得分:3)

您的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

答案 1 :(得分:0)

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