문제

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