Protocol Etching 2: Python3-> 2 Data

I am trying to transfer data from a dataset created in Python3.2, sort it, and then open in Python2.7. However, there is some data that Python2.7 objects to, although it works fine on the data sample, and I was wondering how to understand what is going wrong.

So in Python3.2:

import pickle with open('c:\\test.pickle', mode='wb') as f: pickle.dump(t_array, f, 2) 

Then when reading in Python2.7:

 import pickle f = open('c:\\test.pickle', mode='rb') t_data = pickle.load(f) 

Error:

 File "C:\Python27\lib\pickle.py", line 1378, in load return Unpickler(file).load() File "C:\Python27\lib\pickle.py", line 858, in load dispatch[key](self) File "C:\Python27\lib\pickle.py", line 1217, in load_build setstate(state) TypeError: must be char, not unicode 

The data is an array of dicts, nested no more than two deep, for example:

 {'key3': '3', 'key2': 1.1, 'key1': 1, 'dict': {'dkey2': 2, 'dkey1': 1}} 

What is (possibly) going wrong here? Is there an easy way to see what is causing the problem in the original (large) dataset?

+6
source share
1 answer

The brine is not as good as it may look. Security vulnerabilities and many problems like these.

It is best to create your own save format, for example using json.

+2
source

Source: https://habr.com/ru/post/909365/


All Articles