Frage

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.

War es hilfreich?

Lösung

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.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top