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

The following python code is giving an error:

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

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

1 Answer

+2 votes
by (350k points)
selected by
 
Best answer

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)


...