the goal of my still very simple code is to read in a logfile and store it in a dictionary. My logfile looks like this:
Here you can see the code of my class LogfileHandler. This class simply takes a path where the logfile is stored and converts it into a dictionary.
import jsonpickle
class: LogfileHandler
def __init__(self, filename):
self.lines = self.read_file(filename)
self.log_msg_list = list(self.decode_log_file_lines(self.lines))
def read_file(self, filename):
try:
f = open(filename, 'r')
print('Read from file %s' % filename)
lines = f.readlines()
f.close()
except:
print('File %s does not exist' % filename)
return lines
def decode_log_file_lines(self, lines):
for line in lines:
message = jsonpickle.decode(line)
yield message
If I now run this class in a jupyter notebook, this works without any problem: Picture of my jupyter notebook
However, if I execute this via the CMD with the following main method I get the following error and I don't understand why (It is definitely the same file I´m reading from).
#--- This is the main which I run via the cmd ---
from LogfileHandler import LogfileHandler
if __name__ == "main":
log_file_handler = LogfileHandler('data\log_file.log')
print(log_file_handler.log_msg_list)
Many thanks in advance