【发布时间】:2019-10-14 11:49:33
【问题描述】:
我在从另一个函数内部调用一个函数时遇到了一些问题
这是我的代码:
supported_timeframes = ['1m', '5m', '1h', '1d']
supported_indicators = ['SMA', ... ]
supported_sources = ['open', 'close']
indicator_values = {}
class Indicator:
def __init__(self):
self.indictor = '' # indicator
self.timeframe = '' # timeframe
self.period = 0 # look-back period
self.source = '' # open / close
def error(self, indicator, timeframe, period, source):
if timeframe not in supported_timeframes:
return 'timeframe not supported --', 'supported
timeframes:', supported_indicators
if indicator not in supported_indicators:
return 'indicator not found --', 'supported indicators:',
supported_indicators
if source not in supported_sources:
return 'source is not -- open -- or -- close'
else:
pass
def SMA(self, indicator, timeframe, period, source):
error()
# TODO get candle data from timeframe
# TODO calc requested indicator from candle data and append to
# indicator_values dict
# return indicator
for indicator in indicator_values:
return indicator
我有函数错误首先检查是否在参数中输入了错误的值。
然后我想在 def SMA(...) 函数中调用该函数,因为我将拥有更多函数,每个函数都计算一个类似于 SMA 的指标,所以为了简洁起见,我试图在每个函数中调用 error()而不是每次都复制和粘贴代码。
但是,在执行此操作时,我在 def SMA(...) 中收到一条错误消息,指出 error() 未定义。
如果您能帮助我,请提前非常感谢您!
【问题讨论】: