Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3288304
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:35:32+00:00 2026-05-17T20:35:32+00:00

I have a function named OpenAccount() which takes in the details from the User

  • 0

I have a function named OpenAccount() which takes in the details from the User and appends it to my database dictionary.

I have a database file(module) which is imported in my function file.

I have a function called AppendRecord(key,**dictvalues) which appends values to my database file.

However I am not able to call the function and take in values at run-time to append.
It works fine with Hard-coded values.I’m posting the code.Please help me out.

def AppendRecord(key, **dictvalues):
      salesDept[key] = dict(dictvalues)

and the call for hard coded values is …

AppendRecord('Jill',Name='Jill', Acctype='Savings')

Now when I’ trying to take in all the values along with the key from the user,I am not able to call the function.I’m just a beginner at Python so please pardon me for any errors:

Edited Code:

#!/usr/bin/python

import os       #This module is imported so as to use clear function in the while-loop
import DB                       #Imports the data from database DB.py

def AppendRecord(key, **dictvalues):
        DB.Accounts[key] = dict(dictvalues)

def OpenAccount():           #Opens a new a/c and appends to the database   data-base.

        while True:

                os.system("clear")      #Clears the screen once the loop is re-invoked

#Parameters taken from the user at Run-time so as to make entries in the database and append them


                print '\n','Choose an Account Type'

                print '\n','\n1)Savings Account','\n2)Current Account'

                choice = input('Enter an optin: ')

                if choice == 1:

                        name = raw_input('\nEnter a name: ')
                        depo = input('\nEnter amount(Rs.): ')
                        key = raw_input('\nEnter an alphanumeric-id: ')
                        acc= raw_input('\nEnter the Account-Type: ')

                        AppendRecord(key,Name=name,Initial_deposit=depo,Acctype=acc)

EDIT 1:
The Errors I get are.

 File "/usr/lib/python2.5/shelve.py", line 124, in __setitem__
    self.dict[key] = f.getvalue()
TypeError: 'int' object does not support item assignment

EDIT 2:

Following is the DB.py database file source code.

#!/usr/bin/python

import shelve                   #Module:Shelve is imported to achieve persistence

Victor = {'Name':'Victor Hughes','Acctype':'Savings'}
Xavier = {'Name':'Xavier Bosco','Acctype':'Savings'}
Louis = {'Name':'Louis Philip','Acctype':'Current'}
Beverly = {'Name':'Beverly Dsilva','Acctype':'Current'}

Accounts = shelve.open('shelfile.shl')          #Accounts = {}

Accounts['Louis']= Louis
Accounts['Beverly']= Beverly
Accounts['Xavier']= Xavier
Accounts['Victor']= Victor

Accounts.close()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T20:35:33+00:00Added an answer on May 17, 2026 at 8:35 pm

    Your problem is that the DB module is closing the shelf before you write to it. Get rid of the last line and it will work fine.

    You will also need to provide a function to close it or do so manually.

    #!/usr/bin/python
    
    import shelve                   #Module:Shelve is imported to achieve persistence
    
    
    Accounts = 0
    
    Victor = {'Name':'Victor Hughes','Acctype':'Savings'} #???
    Xavier = {'Name':'Xavier Bosco','Acctype':'Savings'}
    Louis = {'Name':'Louis Philip','Acctype':'Current'}
    Beverly = {'Name':'Beverly Dsilva','Acctype':'Current'}
    
    
    def open_shelf(name='shelfile.shl'):
        global Accounts
        Accounts = shelve.open(name)          #Accounts = {}
        # why are you adding this every time? is this just debugging code?
        Accounts['Louis']= Louis
        Accounts['Beverly']= Beverly
        Accounts['Xavier']= Xavier
        Accounts['Victor']= Victor
    
    
    def close_shelf():
        Accounts.close()
    

    You will now need to call the DB.open_shelf() function before you write to it and the DB.close_shelf function when you are done. I would recommend calling them at the beginning and end of your program respectively.

    You’ll note that this is really just wrapping shelve and adding pretty much zero value. I would scrap the whole DB module and just use shelve directly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have made one function named SetControls(control controlName) which only takes control as a
I have a function named resize, which takes a source array, and resizes to
I have a function which takes a parameter named p_categories , of type smallint[]
We have a JavaScript function named move which does just windows.location.href = any given
In my HTML file, I have a JavaScript function named CheckCaptcha. I am using
Suppose I have a function named caller, which will call a function named callee:
I have function named: - (void) AddSortedCustomFeed :(NSMutableArray*) rssList; this function adds items(Articles) from
In my project I have a function named GetObject that is wrapped in one
I have a jQuery setInterval function named timerIncrement that times out (stops incrementing the
hai , I have a javascript function named as sss() . I want to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.