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

The following python code is giving an error:

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

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

1 Answer

0 votes
by (16.9k 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)

...