dusa
dusa

Reputation: 820

Text editor readable pickle format?

I am working with a repository where there is a pickle file that shows the names of the videos in the dataset and the number of frames of each video. I can open it using a text editor and the format is as below:

(dp0
S'v_Lunges_g07_c01.avi'
p1
I248
sS'v_Haircut_g18_c04.avi'
p2
I263
sS'v_Bowling_g21_c03.avi'
p3
I179
sS'v_FrontCrawl_g04_c04.avi'
p4
I328
sS'v_Biking_g15_c05.avi'
p5
I239
sS'v_Swing_g08_c03.avi'
I289
s.

So I want to create a similar one in the same format, but when I create a ditionary and save it to a pickle file 1. this is not the format it is stored in 2. It is not readable with a text editor.

What am I missing here? Why can some pickle files be read and edited in text editors, while others can not? What do I need to do to get this format for the pickle file (obviously not just text editing but through python)?

Upvotes: 0

Views: 2960

Answers (1)

Serge Ballesta
Serge Ballesta

Reputation: 148965

There are different versions for the pickle protocol. Only version 0 is human readable. But anyway, if you want to use a text editor over it, you should considere json format which is intended to be human readable, while pickle is not.

If all you need is to generate human readable pickle files and are aware that it is a little documented format, just declare the 0 protocol:

pickle.dump(obj, protocol=0)

Upvotes: 1

Related Questions