[Tutor] [Python 3.5] TypeError: a bytes-like object is required, not 'str' PICKLE

Peter Otten __peter__ at web.de
Fri Apr 7 06:28:21 EDT 2017


Allan Tanaka via Tutor wrote:

> Hi
> I have added b so that it translates into bytes object. save_cPickle part
> is not problem... But i still get an error when coming into load_cPickle
> for this function: Dataset.save_part_features('categorical_counts',
> Dataset.get_part_features('categorical')) although i have defined b in
> save_cPickle
> 
> THE CODE:

> import _pickle as cPickle

Why not just

import pickle

?

> def load_cPickle(filename):
>     with open(filename) as f:
> 
>         return cPickle.load(f)

I've no idea what your code is supposed to do, and my attempt to run it 
didn't get this far -- but you have to open the file in binary mode

with open(filename, "rb") as f: ...

to load the pickled data.



More information about the Tutor mailing list