Hi sorry this seems to be a very bad question but whenever i create a json txt file in python and write to it, it only saves temporarily. For example, i have a for loop to write text to the file over the amount of times the user wants it to. I know it does it multiple times because i have a counting function to print each time it does it, but the text file that is being written to only saves one loop. So say i want to print the numbers of every time i do the loop, i may ask it to run 4 times, the numbers that should be printed are 0, 1, 2, 3, the only number i see printed to the file at the end is 3 as i keep writing over my data. Here is my code so someone can assist me and like always any and all help is greatly appreciated.
def create_tasks():
num_tasks = int(num_tasks_entry.get())
global size
num = 0
for num in range(0, num_tasks):
data = {}
data['task'] = []
data['task'].append({
'profile': profiles_select.get(),
'task_id': num,
'product_link': productlink_entry.get(),
'delay': int(delay_entry.get()),
})
num = num + 1
with open('tasks.txt', 'w', encoding='utf-8') as outfile:
json.dump(data, outfile, indent=2)
Another example, in my code i want the out put file to be this information printed the amount of times the user selects.