I have a problem, but I can't figure out where it is going wrong.
What I am getting from this is that there is a empty thing or a space but there definitively isn't any in my text file. The goal of my code is to add money to a text file separated by a comma and turn that into an integer list.
Bonus: If you know anything about Pycharm how do you get rid of the '>?'
when typing in an input.
My error:
File "C:/Users/hayde/PycharmProjects/Finance/Money.py", line 32, in <listcomp>
int_tot = [int(i) for i in str_tot]
ValueError: invalid literal for int() with base 10: ''
My code:
def add_money():
money = str(input("Amount: "))
#if '' in money: #if i run this it loops forever
#return add_money()
with open(r"C:\Users\hayde\OneDrive\Desktop\account.txt", 'a') as account:
account.write(',' + money)
with open(r"C:\Users\hayde\OneDrive\Desktop\account.txt", 'r') as account:
if account.read(1) == ',':
print("Please clear account file, then have 0 be the only value in file")
return
for cash in account:
str_tot = cash.split(',')
int_tot = [int(i) for i in str_tot]
return int_tot