Note that there are some explanatory texts on larger screens.

plurals
  1. POpython object in dictionary
    primarykey
    data
    text
    <p>I am trying to save the object <code>candle</code> in the dictionary <code>candlebuffer</code>, however it gives me the error below. I am struggling; what is incorrect with my syntax?</p> <pre><code> class Observer: def __init__(self): self.listeners = [] def attach(self, listener): if not listener in self.listeners: self.listeners.append(listener) def notify(self, event): for listener in self.listeners: listener.update(event) class CandleGenerator(Observer): def __init__(self,freq): Observer.__init__(self) self.freq = freq self.candle = Candle() def update(self,tick): self.candle.addTick(tick,self.freq) if keyfunc(self.candle.timestamp,self.freq) != self.candle.ref_timestamp: self.notify(self.candle) self.candle = Candle() class CandlePrinter: def update(self, candle): print "Bougie&gt;&gt;&gt;&gt;&gt;&gt; freq: %s %s %s %s %s %s %s %s %s " % (candle.freq,candle.last_price,candle.volume, candle.timestamp, candle.ref_timestamp, candle.open_price,candle.high_price,candle.low_price, candle.last_price) class CandleBuffer: def __init__(self,candle): self.candlebuffer={0: candle} def update(self,candle): self.candlebuffer[candle.timestamp]= candle print self.candlebuffer print('begin') tickGenerator = TickGenerator() candleGenerator1 = CandleGenerator(1) candlePrinter = CandlePrinter() candleBuffer = CandleBuffer(5) tickGenerator.attach(candleGenerator1) candleGenerator1.attach(candlePrinter) candleGenerator1.attach(candleBuffer) tickGenerator.generate() </code></pre> <p>It gives the following output:</p> <pre><code>TypeError: __init__() takes exactly 2 arguments (1 given) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload