I'm creating a program making a "to do list". I prepared a function which writes a list of items entered by user. Then, using decorator, I want every item of the list to be added to txt file. I struggle with writing items of the lists one by one to the file. Using for loop in wrapper function doesn't work - nothing is shown on the log after running
def decorator(func):
def wrapper(*args):
with open("to_do_list.txt", "a") as l:
for i in range(len(args)):
l.write(f"{func(*args[i])} \n")
return wrapper
@decorator
def to_do():
print("TO DO LIST")
status = True
list = []
while status:
x = input("Add a task to a list: ")
list.append(x)
q = input("Do you wanna continue typing (Y), or quit (Q)?").lower()
if q == "n":
status = False
return list
to_do()