Ich habe ein Problem beim Laden einer gebeizten Datei in Python3. Siehe folgenden Code:Fehler beim Laden der gebeizten Datei
#!/usr/bin/env python3
import csv,operator
import pickle
import os.path
pathToBin = "foo/bar/foobar.bin"
pathToCSV = "foo/bar/foobar.csv"
if os.path.isfile(pathToBin):
print("Binary file already on harddrive, loading from there")
transactions = pickle.loads(open(pathToBin, "rb"))
else:
csvIn = open(pathToCSV,'r')
reader = csv.reader(csvIn)
header = next(reader)
header = header[0].split(";")
print("Reading file")
transactions = []
for row in reader:
# read file.
# transactions contains now lists of strings: transactions = [ ["a","b","c"], ["a2","b2","c3"], ...]
print("Dumping python file to harddrive")
myPickleFile = open(pathToBin,'wb')
pickle.dump(transactions, myPickleFile, protocol=pickle.HIGHEST_PROTOCOL)
# do some more computation
Das Speichern der Datei funktioniert problemlos. Es ist jedoch Laden gibt mir die folgende Fehlermeldung:
transactions = pickle.loads(open(pathToBin, "rb"))
TypeError: '_io.BufferedReader' does not support the buffer interface
Da ich python3, werden Zeichenfolgen unterschiedlich behandelt werden. Daher gebe ich speziell die Option "b" zum Speichern/Laden. Jeder hat eine Idee, warum das nicht funktioniert?