This is a test program for my big program. It says I get a EOerror.

import pickle
list = ["11", "22"]
outFile = open("save.txt", "wb")
pickle.dump(list, outFile)
outFile.close
inFile = open("save.txt", "rb")
inFile = pickle.load(inFile)
print(inFile)
yea = inFile[1]
print(yea)
input("")

It gives me an error on line 7.

有帮助吗?

解决方案

outFile.close

You didn't call the method!

In the future, note that the preferred way of opening files is

with open(name, mode) as f:
    do_whatever(f)

This handles closing the file at the end of the with block, no matter how control leaves it.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top