+2 votes
in Programming Languages by (66.4k 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 (286k points)
selected ago 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)