[Tutor] getting keyboard input to dictionary (newbie ques)

Frank Holmes flash1210@hotmail.com
Wed, 09 Jan 2002 19:14:15 -0800


  I am writing a simple phone number database type program. I am using 
dictionaries to handle variations in the way the names can be entered ie: 
jones:555-5555, Jones:555 5555, etc.
   I can get it to return names or quit in response to keyboard input from a 
menu, but cannot figure out how to add entries to the dictionary from there. 
Help!

     Def add_name():
     print "enter name"
     n=raw_input()
     print "enter number"
     m=raw_input()
     d1[n]=m

while 1:
     print "some greeting"
     print "type name to search"
     print "type 'add' to add names or 'quit' to exit"
     x=raw_input()
     if x=='quit':
          break
     d1={'a name':'1111', 'another name':'2222', 'A. Name':'1111'}
     if x in d1.keys():
          print d1[x], x
     if x=='add':
          add_name()


    It will let me retrieve and quit, and when I enter 'add' it will print 
as if it is working but the entries are not added to the dict.
   I have tried converting the raw-input() value to a string using the 
str.() then using that identity in the d1[n]=m but still won't update.
   I'm missing something obvious... help.





_________________________________________________________________
Chat with friends online, try MSN Messenger: http://messenger.msn.com