Domanda

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.

È stato utile?

Soluzione

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top