So I just received an error that I kinda don't understand what is the reason of.
Traceback (most recent call last):
File "C:\Users\utils.py", line 657, in script
logger.warn('Wopsiy! No word found!')
File "C:\Users\utils.py", line 30, in warn
sys.stdout.write("{}{} {}".format(self.__timestamp(), '[' + self.name + '] -', colored(text, "yellow")))
File "C:\Program Files\Python36\lib\site-packages\colorama\ansitowin32.py", line 40, in write
self.__convertor.write(text)
File "C:\Program Files\Python36\lib\site-packages\colorama\ansitowin32.py", line 141, in write
self.write_and_convert(text)
File "C:\Program Files\Python36\lib\site-packages\colorama\ansitowin32.py", line 166, in write_and_convert
self.write_plain_text(text, cursor, start)
File "C:\Program Files\Python36\lib\site-packages\colorama\ansitowin32.py", line 174, in write_plain_text
self.wrapped.write(text[start:end])
File "C:\Program Files\Python36\lib\site-packages\colorama\ansitowin32.py", line 40, in write
self.__convertor.write(text)
File "C:\Program Files\Python36\lib\site-packages\colorama\ansitowin32.py", line 141, in write
self.write_and_convert(text)
File "C:\Program Files\Python36\lib\site-packages\colorama\ansitowin32.py", line 169, in write_and_convert
self.write_plain_text(text, cursor, len(text))
File "C:\Program Files\Python36\lib\site-packages\colorama\ansitowin32.py", line 174, in write_plain_text
self.wrapped.write(text[start:end])
As I can see it has something with the logger that I have created myself that looks like:
Utils class
from datetime import datetime
from termcolor import cprint, colored
import sys
import colorama
class Logger:
def __init__(self,name):
colorama.init()
self.name = name
@staticmethod
def __timestamp():
timestamp = str(datetime.now().strftime("[%H:%M:%S.%f")[:-3]+"]")
return timestamp
def warn(self, text):
sys.stdout.write("{}{} {}".format(self.__timestamp(), '[' + self.name + '] -', colored(text, "yellow")))
sys.stdout.write("\n")
sys.stdout.flush()
And basically I made also a simple code of how my code looks like as well:
from utils import Logger
logger = Logger('Script')
def main():
logger = Logger("product_info")
word = ['Nope', 'There', 'Is', 'No', 'Word']
while True:
try:
for _ in infinity():
if 'Hello' in word:
print('WORKS!!')
else:
logger.warn('Wopsiy! No word found!')
time.sleep(1)
except Exception as err:
print(err)
time.sleep(1)
continue
So the problem is that after a while it gives me an error of maximum recursion depth exceeded while calling a Python object but I only get it whenever I print out except Exception as err: but when I see through a console it gives me the output that is given at the top.
The question is now that I have actually no idea what the cause of it is.
Edit
from datetime import datetime
from termcolor import cprint, colored
import sys
import colorama
colorama.init()
class Logger:
def __init__(self,name):
self.name = name
@staticmethod
def __timestamp():
timestamp = str(datetime.now().strftime("[%H:%M:%S.%f")[:-3]+"]")
return timestamp
def warn(self, text):
sys.stdout.write("{}{} {}".format(self.__timestamp(), '[' + self.name + '] -', colored(text, "yellow")))
sys.stdout.write("\n")
sys.stdout.flush()