I'm fairly new to python so please correct me if my question does not make sens.
I am writing a small script, which should check some data and log those that failed. To have a better overview I am maintaining two files. One with my main function and the other with the other functions.
To log my failed data I have this class:
class OutputLog():
def __init__(self):
self.errorLog = []
def log(self, item: str): #write data to errorLog if called
self.errorLog.append(item)
self.errorLog.append('\n')
def write(self): #return errorLog
return self.errorLog
In my check function I call OutputLog.log() like this:
####### Check Data ########
class Check:
def __init__(self, sortedData):
self.sortedData = sortedData
## Check if name got spaces and log them
def nameSpace(self):
out = OutputLog()
for column in self.sortedData:
item = column[0]
if ' ' in item:
out.log(item) #Call Output log
else:
continue
In my main function, which is in the other .py file (don't really know if this makes a huge difference) I want to get the error log like this:
import my_functions
def main():
out = my_functions.OutputLog()
c = my_functions.Check()
c.nameSpace()
print(out.write())
But like this my error log is still empty. Is there a way how I can only have one instance of the OutputLog class or do I need to make the errorLog variable public?
If anyone knows a better way to do this I would love to hear your recommendations.