python未定义变量

为什么在方法更新中未定义变量freq?
我在init上调用方法Candle,并且此方法包含freq?

class candle:
    def __init__(self):
        self.freq = None
        self.open_price = None
        self.high_price = None
        self.low_price = None
        self.last_price = None
        self.volume = 0

    def addTick(self,tick):
        if self.open_price is None:
            self.open_price = tick.price
        if self.high_price is None or tick.price >self.high_price:
            self.high_price = tick.price
        if self.low_price is None or tick.price <self.low_price:
            self.low_price = tick.price   
        self.last_price = tick.price
        self.volume = self.volume +1


    def update(self,tick):
        self.candle.addTick(tick)
        if keyfunc(current_time,freq) != reference_timestamp[freq]:
            self.notify(self.candle)
            self.candle = candle()

解决方法:

Python中没有隐式的self,在访问成员变量时必须显式.

if keyfunc(current_time,freq) != reference_timestamp[freq]:

应该

if keyfunc(current_time, self.freq) != reference_timestamp[self.freq]:

如果不确定reference_timestamp是全局的,则不确定该在哪里定义.

上一篇:c-如何在Eclipse中启动gdb调试之前运行linux脚本


下一篇:java-如何从Eclipse中的Maven构建中调试测试?