[Tutor] A problem with the shelve module

Mark Kels Mark.Kels at gmail.com
Sun Sep 5 17:56:13 CEST 2004


Hi all,
Its my again (the guy with the bad english... :-/ ).

I started to build a personal organizer useing the module "shelve".
The problem is that I get an error in the module (?!) .
here is the code of the function that makes the problem:

[Start of code]
#The adress book function
def Address():
    print
    print "1.Open a book"
    print "2.View a book"
    print "3.Add name"
    print "4.Delete name"
    print "5.Edit name"
    print "6.Back"
    print
    Achoice=raw_input(">>> ")
    book=shelve.open("Address book")
    if Achoice=="3":
        addname=raw_input("Name: ")
        phone=raw_input("Phone number(type 'none' if you wabt to add
Phone number later): ")
        Addressnum=raw_input("Address(type 'none' if you wabt to add
Address later): ")
        ICQ=raw_input("ICQ number(type 'none' if you want add ICQ later): ")
        book[addname]=(addname,phone,Addressnum,ICQ)
        Address()
    elif Achoice=="2":
        namecheck=raw_input("Enter the name you want to view: ")
        book[namecheck]
        Address()
[End of code]

And the error I get is:
Traceback (most recent call last):
[Start of code]
Enter the name you want to view: MarkK
  File "C:\ab.py", line 57, in ?
    startmenu()
  File "C:\ab.py", line 45, in startmenu
    Address()
  File "C:\ab.py", line 28, in Address
    Address()
  File "C:\ab.py", line 28, in Address
    Address()
  File "C:\ab.py", line 32, in Address
    Address()
  File "C:\ab.py", line 28, in Address
    Address()
  File "C:\ab.py", line 31, in Address
    book[namecheck]
  File "C:\DOCUME~1\AMP-TECH\DESKTOP\MARK\program\lib\shelve.py", line 118, in _
_getitem__
    f = StringIO(self.dict[key])
  File "C:\DOCUME~1\AMP-TECH\DESKTOP\MARK\program\lib\bsddb\__init__.py", line 1
16, in __getitem__
    return self.db[key]
KeyError: 'MarkK'
[End of code]

Thanks!!


More information about the Tutor mailing list