+2 votes
in Programming Languages by (59.3k points)

The following python code is giving an error:

data = pickle.load('testData.pkl')

TypeError: file must have 'read' and 'readline' attributes.

1 Answer

+1 vote
by (232k points)

The load() function of pickle module takes the file object as an argument. Here you are passing the file name as an argument and hence it's is giving the error. Use the following code to fix the error:

with open('testData.pkl','rb') as f:
    data = pickle.load(f)