質問

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