问题
I'm using Python 3.6 and Spyder (Anaconda). I have tried many things but nothing worked out. I don't know why this error is coming always to me while loading with pickle.
filename = "allfeatures.txt"
allfeatures = open(filename, 'r').read()
with open(filename) as f:
allfeatures = list(f)
allconcat = np.vstack(list(allfeatures.values()))
TypeError Traceback (most recent call last)
AttributeError: 'list' object has no attribute 'values'
回答1:
You need to open your file as a binary file:
pickle.loads(open("accounts.txt", 'rb').read())
Otherwise, it's using an str
to read the data.
来源:https://stackoverflow.com/questions/53052551/typeerror-a-bytes-like-object-is-required-not-str-while-loading-with-pickle