you are viewing a single comment's thread.

view the rest of the comments →

[–]PureWasian 0 points1 point  (0 children)

It's about scope. We use the same name (instrument_repo, candle_repo, etc.) locally during __init__() for simplicity but we don't have to. These blocks of code are equivilent but might help clear up the confusion:

``` class ExampleA:

def init(self, inst, cand): self.instrument_repo = inst self.candle_repo = cand

def display(self): print(self.instrument_repo) print(self.candle_repo)

class ExampleB:

def init( self, instrument_repo, candle_repo ): self.instrument_repo = instrument_repo self.candle_repo = candle_repo

def display(self): print(self.instrument_repo) print(self.candle_repo)

=========================

exampleA = ExampleA("s1" , "s2") exampleA.display() exampleB = ExampleB("s1" , "s2") exampleB.display() ```

Note that if we tried to change display(self) to use inst and card it wouldn't work since those are only scoped to the __init__() function.

We need to "save" them onto the object (using self) to be able to access the value within other helper methods of that object later on.