Jul-26-2019, 07:12 PM
My question is rather simple and straight forward.
I've got this piece of code:
I've got this piece of code:
import shelve Info=shelve.open("Info") data={} def add(): while True: print ("User ID: ") usr=input(">>> ") print ("User Name: ") name=input(">>> ") print ("User Ager: ") age=input(">>> ") print ("User Gender: ") gender=input(">>> ") datos[usr]=[name, age, gender] print ("Add another entry?") op=input(">>> ") if str(op)=="s": del(name) del(age) del(gender) continue else: break add() Info["Data"]=data Info.close()And this other one:
import shelve Info=shelve.open("Info") pref=["Name: ", "Age: ", "Gender: "] for i, j in Info["Data"].items(): print (i) for k, l in enumerate(j): print ("\t"+str(pref[k]).ljust(10)+str(l).rjust(15)) print () Info.close()I know the error is in initializing the dict "data" as and empty dict every time I run the script, but I can't figure out how to store data and add any new data to the already stored.