解决 python3.X TypeError: write() argument must be str, not bytes

import pickle as p

output_model_file = 'saved_model.pkl'
with open(output_model_file,'w') as f:
    p.dump(linear_regressor,f)
TypeError: write() argument must be str, not bytesp
 
  

In Python 3 it makes a difference whether you open the file in binary or text mode. Just add the bflag to make it binary:

with open('random.bin','wb') as f:

This works in Python 2 too.

 

你可能感兴趣的:(python,学习)