yannis assael | the blog

  • Home
  • About
  • Categories
    • Android
    • Computing
    • iOS
    • Machine Learning
    • MacOSX
  • GitHub
  • Mobile Apps
  • yannisassael.com


Open Python 2 Pickle in Python 3

Written by iassael on 30/03/2016. Posted in computing

Opening a pickle from Python 2 in Python 3 will probably result either:

TypeError: 'str' does not support the buffer interface

or

UnicodeDecodeError: 'ascii' codec can't decode byte 0xab in position 0: ordinal not in range(128)

to solve that you can just use the following code setting the defualt encoding:

import pickle
import gzip
import numpy as np
with open('var/python2pickle.pkl', 'rb') as f:
    data = pickle.load(f, encoding='latin1')
    print(data)


        
        

Tags: ascci, decode, encode, pickle, python, python 2, python 3

Trackback from your site.

Leave a comment