I am working on function in python 3.8 to store my list of Ideas inside ideas.txt file and after getting new entry updating list in file. For some reason it works only for first entry and then becomes messy ie: [(1, '["[\'aaa\']", \'sss\']'), (2, 'ddd')]
here is my code:
def add_idea():
while True:
with open("ideas.txt","r") as f:
updated_list = f.readlines()
idea=input("What is your new idea?"+"\n")
idea=str(idea)
updated_list.append(idea)
"\n".join(updated_list)
f.close()
with open("ideas.txt","w") as f:
f.write(str(updated_list))
f.close()
num_list = list(enumerate(updated_list,1))
print(num_list)
I'm new to python and programming so please be kind ;)
def add_idea():
while (idea := input("What is your new idea?"+"\n")):
with open("ideas.txt","a") as f:
print(idea, file=f)
Some notes: