ich habe ein kleines problem mit dem modul "pickle" undzwar will es nicht richtig funktionieren bzw nicht richtig laden, ob es richtig speichert weiß ich auch nicht so recht, da ich ja auch nichts laden kann. Es geht eigentlich nur um die ersten beiden funktionen "saveVoc()" und "loadDict()" der Rest funktioniert einwandfrei, wenn ihr natürlich noch Verbesserungsvorschläge habt, immer her damit! Hier erstmal mein Code:
Code: Alles auswählen
import pickle
def saveVoc():
f = file('dict.dmp', 'w')
pickle.dump(dict,f)
f.close()
def loadDict():
f = file('dict.dmp', 'r')
pickle.load(f)
f.close()
def writeVocIntoDict():
word = raw_input('\nEnter the word: ')
transword = raw_input('\nEnter the translation: ')
dict[word] = transword
# translated word as key
dict[transword] = word
saveVoc()
def menu():
print '1) Add vocabulary'
print '2) Translate a word'
sel = int(raw_input ('\nWhat do you want? '))
if sel >= 1 and sel < 3:
if sel == 1:
writeVocIntoDict()
elif sel == 2:
word = raw_input('Enter the word: ')
if word in dict:
print dict[word]
else:
print 'vocabulary not known'
else:
print 'Error! Only numbers from 1 to 2 are allowed!'
menu()
dict = {}
print '\nDictionary 1.000.000 by read error\n**********************************'
loadDict()
menu()