无法从腌制的文件中加载变量

时间:2018-07-24 13:18:23

标签: python serialization pickle

import pickle
myDictOne = { "Key1": "Value1", "Key2": "Value2", "Key3": "Value3" }
myMovieTuple = (
"DDLJ",
"SRK",
"1993",
(
    (1, "Zara sa jhoom lu main"),
    (2, "Na jane mere "),
    (3, "Ghar a ja pardesi"),
    (4, "Mehdi laga ke rakhna")
)
)
myList = ["One", 3.5, 7, "two"]

with open('VariblesFile.pickle', 'wb') as myPickleFile:
    pickle.dump(myDictOne, myPickleFile)
    pickle.dump(myMovieTuple, myPickleFile)
    pickle.dump(myList,  myPickleFile)

with open('VariblesFile.pickle', 'rb') as myPickled_File:
    myNewDictOne = pickle.load(myPickled_File)
    myNewMovieTuple = pickle.load(myPickled_File)
    myNewList = pickle.load(myPickled_File)

print(myNewDictOne)
for i in myNewMovieTuple:
   for j in i:
        print(j)
print(myNewList)

如果我执行此程序,则会收到以下提到的错误消息。基本上创建了pickle文件,但是当我尝试重新加载变量时,那是行不通的。...请帮助

Traceback (most recent call last):
None
  File "E:/myNewPythonDir/CompletePythonDeveloperCourse/Module10/myOwnPickle.py", line 32, in <module>
    for i in myNewMovieTuple:
TypeError: 'NoneType' object is not iterable

Process finished with exit code 1

0 个答案:

没有答案