Every time I pull the JSON file during the next program execution/session, the previous data is overwritten. Ultimately, what I'm trying to do is save my data to a file and retrieve it the next time I want to run the program. I want to append data to the list whenever I run the program.
import json
import os.path
income = []
def file_exists():
if os.path.exists('income.json') == True:
with open('income.json') as f:
income = json.load(f)
else:
pass
def desire_func():
x = input('What do you want to do? ')
if x != 'n':
transactions()
print(income)
else:
return
def transactions():
with open('income.json', 'w') as g:
entry = float(input('Transaction info: '))
income.append(entry)
json.dump(income, g)
desire_func()
file_exists()
transactions()
print(income)
Any help would be greatly appreciated as I've attempted to tackle this from multiple angles and always run into a different issue. Initially, I was trying to pickle the data and that seemed far less robust, but I am open to anything that may work.
Thanks in advance for your help.
EDIT: Added in desire_func() so you can easily add multiple times to the same list (income) while troubleshooting.