【发布时间】:2020-11-15 15:03:30
【问题描述】:
我有一个带有__init__ 方法的类,我在其中定义了一些变量,以及一个方法AddSignalSpectrum:
class SpectrumGraph:
# Properties
def __init__(self):
self.PlotHeight= 300
self.PlotWidth = 800
self.xRangeMin = -10
self.xRangeMax = 10
self.yRangeMin = -0.1*(self.xRangeMax - self.xRangeMin)
self.yRangeMax = 0.9*(self.xRangeMax -self.xRangeMin)
def AddSignalSpectrum(
self,
name,
Type,
CenterPosition,
Bandwidth=2,
Height = self.yRangeMax*0.8,
Color = "#0000FF",
LineWidth = 2,
AbscissaSymbol = '$\omega_0$',
ShowLegend = False):
# Rest of the method
我想要的是为该方法提供 self.yRangeMax*0.8 的默认值,但是当我这样做时,我收到一条错误消息,指出未定义“self”。我可以在方法中使用self 的属性就好了,但它似乎在方法定义的参数中不起作用。我认为这是某种名称空间问题,但找不到解决方法。可能我只是不确定要搜索什么。
【问题讨论】: