I have opened a shelve using the following code:
#!/usr/bin/python
import shelve #Module:Shelve is imported to achieve persistence
Accounts = 0
Victor = {'Name':'Victor Hughes','Email':'[email protected]','Deposit':65000,'Accno':'SA456178','Acctype':'Savings'}
Beverly = {'Name':'Beverly Dsilva','Email':'[email protected]','Deposit':23000,'Accno':'CA432178','Acctype':'Current'}
def open_shelf(name='shelfile.shl'):
global Accounts
Accounts = shelve.open(name) #Accounts = {}
Accounts['Beverly']= Beverly
Accounts['Victor']= Victor
def close_shelf():
Accounts.close()
I am able to append values to the shelve but unable to modify the values. I have defined a function Deposit() from which I would like to modify the data present in the shelve.But it gives me the following error:
Traceback (most recent call last):
File "./functest.py", line 16, in <module>
Deposit()
File "/home/pavitar/Software-Development/Python/Banking/Snippets/Depositfunc.py", line 18, in Deposit
for key in Accounts:
TypeError: 'int' object is not iterable
Here is my Function:
#!/usr/bin/python
import os #This module is imported so as to use clear function in the while-loop
from DB import * #Imports the data from database DB.py
def Deposit():
while True:
os.system("clear") #Clears the screen once the loop is re-invoked
input = raw_input('\nEnter the A/c type: ')
flag=0
for key in Accounts:
if Accounts[key]['Acctype'].find(input) != -1:
amt = input('\nAmount of Deposit: ')
flag+=1
Accounts[key]['Deposit'] += amt
if flag == 0:
print "NO such Account!"
if __name__ == '__main__':
open_shelf()
Deposit()
close_shelf()
I'm new to Python.Please help.Correct me if I'm wrong.I need someone to give a little bit of explanation as to the functioning of this code.I'm confused.