In my project I have a Strategy which stores LOGS into a dataframe. A Strategy is a succession of Block instances. Each Block can writeLog().
What I want is that each block points to the Strategy.LOGS to append lines in it.
Here is my minimal code:
import pandas as pd
class Block:
def __init__(self, logger):
self.logger = logger
def check(self):
self.writeLog('test!')
def writeLog(self, message):
self.logger = self.logger.append({'Date':10, 'Message':message, 'uid':11}, ignore_index=True)
class Strategy:
def __init__(self):
self.LOGS = pd.DataFrame(columns=['Date', 'Message', 'uid'])
self.blk1 = Block(logger=self.LOGS)
self.blk2 = Block(logger=self.LOGS)
def nxt(self):
self.blk1.check()
self.blk2.check()
strat = Strategy()
for i in range(0,5):
strat.nxt()
print(strat.LOGS)
print(strat.blk1.logger)
print(strat.blk2.logger)
These are the outputs:
>>Empty DataFrame
Columns: [Date, Message, uid]
Index: []
>> Date Message uid
0 10 test! 11
1 10 test! 11
2 10 test! 11
3 10 test! 11
4 10 test! 11
>> Date Message uid
0 10 test! 11
1 10 test! 11
2 10 test! 11
3 10 test! 11
4 10 test! 11
I don't understand why the attribute LOGS of Strategy is not appended. I thought I was pointing into strat.LOGS by writing logger=self.LOGS.
Thanks for your answers.