2016-03-21 14 views
0

Ich versuche, ein Wörterbuch in einer Datei zu speichern.Warum bekomme ich immer diesen cPickle-Fehler?

Dieser Teil meines Codes ist:

Accounts={} 
if username not in Accounts: 
    Accounts[username]=password 
    database=open("my_mail_database", "w") 
    pickle.dump(Accounts, database) 
    database.close() 

Und ich bekomme immer diese Fehlermeldung:

Traceback (most recent call last): 
File "C:\Python34\lib\tkinter\__init__.py", line 1538, in __call__ 
return self.func(*args) 
File "C:\Python34\python 3.4\my_gmail2.pyw", line 51, in submit_account 
pickle.dump(Accounts, database) 
TypeError: must be str, not bytes 

Kann mir jemand sagen, was ist das Problem mit meinem Code?

+5

http://stackoverflow.com/questions/13906623/using-pickle-dump-typeerror-must-be-str- Nicht-Bytes – zezollo

Antwort

1

Versuchen Sie das mal:

Accounts={} 
if username not in Accounts: 
    Accounts[username]=password 
    database=open("my_mail_database", "wb") 
    pickle.dump(Accounts, database) 
    database.close() 

Sie haben Datei zu öffnen, mit wb

Verwandte Themen