# geek_translator3.py # Pickle import pickle
# Open Dictionary geekfile = open('geekdictionary3.txt', 'r+') new_geeks = pickle.load(geekfile) geekterms = new_geeks.keys() geekterms.sort() # start choice = None while choice != "0": print \ """ Geek Translator 0 - Quit 1 - Look Up a Geek Term 2 - Add a Geek Term 3 - Redefine a Geek Term 4 - Delete a Geek Term 5 - List of Terms """ choice = raw_input("Choice: ") print # exit if choice == "0": print "Good-bye." # get a definition elif choice == "1": term = raw_input("What term do you want me to translate?: ") if term in new_geeks: definition = new_geeks[term] print "\n", term, "means", definition else: print "\nSorry, I don't know", term # add a term-definition pair elif choice == "2": term = raw_input("What term do you want me to add?: ") if term not in new_geeks: definition = raw_input("\nWhat's the definition?: ") new_geeks[term] = definition geekterms.append(term) geekterms.sort() print "\n", term, "has been added." else: print "\nThat term already exists! Try redefining it." # redefine an existing term elif choice == "3": term = raw_input("What term do you want me to redefine?: ") if term in new_geeks: definition = raw_input("What's the new definition?: ") new_geeks[term] = definition print "\n", term, "has been redefined." else: print "\nThat term doesn't exist! Try adding it." # delete a term-definition pair elif choice == "4": term = raw_input("What term do you want me to delete?: ") if term in new_geeks: del new_geeks[term] geekterms.remove(term) print "\nOkay, I deleted", term else: print "\nI can't do that!", term, "doesn't exist in the dictionary." # list of terms elif choice == "5": print geekterms # some unknown choice else: print "\nSorry, but", choice, "isn't a valid choice." # geek speak link print "\tTo learn to speak geek visit" print "\n\t\thttp://www.youtube.com/watch?v=7BpsXZpAARk" # 133t speak links print "\n\n\tTo learn to 1337 speak visit" print "\n\t\thttp://linuxreviews.org/howtos/l33t/" print "\n\t\t\t\tor" print "\n\t\thttp://textozor.com/hacker-text/" # save dictionary pickle.dump(ldict, open('geekdictionary.txt', 'r+')) # close file geekfile.close() raw_input("\n\nPress the enter key to exit.") When I run it, the system gave me the feedback below: Traceback (most recent call last): File "geek_translator3.py", line 4, in <module> import pickle File "/usr/local/lib/python2.5/pickle.py", line 13, in <module> AttributeError: 'module' object has no attribute 'dump' I don't understand, I don't write anything about pickle.py, why it mentioned? what's wrong with "import pickle"? I read many examples online whose has "import pickle", they all run very well. Thank you! -- Shurui Liu (Aaron Liu) Computer Science & Engineering Technology University of Toledo _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor