Ant*_*mes 1 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_
Run Code Online (Sandbox Code Playgroud)
每当我尝试在init 中指定默认值时,我都会收到类似这样的运行时错误
运行时错误(SyntaxErrorException):此处必须指定默认值 File "", line 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):
Run Code Online (Sandbox Code Playgroud)
应采用以下形式:
def __init__(self,_name,surfacename_,performance_name,_integrationmode,No_parallel,No_series,performance_type = "PhotovoltaicPerformance:Simple"):
Run Code Online (Sandbox Code Playgroud)
类似的问题在这里。