如何定义将输出到pickle文件的格式(字符串,整数等)? [英] How can I define the format that will be output (string, integer etc) to pickle file?

查看:291
本文介绍了如何定义将输出到pickle文件的格式(字符串,整数等)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个存储库,该存储库中有一个pickle文件,该文件显示数据集中视频的名称以及每个视频的帧数.

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.

(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.

在StackOverflow的一些帮助下,我了解到可以使用pickle.dump(obj,protocol = 0)

With some help from StackOverflow I learnt that I can get a similar file (text editor readable) using pickle.dump(obj, protocol=0)

但是,我找不到有关所用格式的信息.我假设S-对应于视频名称和I248,例如对应于Integer-value:248(无帧).但是,当我尝试一个由字符串和整数组成的字典的迷你样本时,我得到了:

However, I fail to find information about the format used. I assume the S- corresponds to videonames and I248, for example corresponds to Integer-value:248 (no of frames). When I try a mini sample of a dictionary of Strings and integers however, I get this:

(dp0
VLaika
p1
L16L
sVBarco
p2
L12L
sVFilou
p3
L8L
sVLuna
p4
L5L
sVBalou
p5
L9L
sVSkippy
p6
L10L
sVOzzy
p7
L3L
s.

我这样定义字典: dogs_dict = {"Ozzy":int(3),"Filou":int(8),"Luna":int(5),"Skippy":int(10),"Barco":int(12),"Balou :int(9)," Laika:int(16)}

I define the dictionary as such: dogs_dict = { "Ozzy": int(3), "Filou": int(8), "Luna": int(5), "Skippy": int(10), "Barco": int(12), "Balou": int(9), "Laika": int(16) }

如果强制转换不起作用,如何定义将其输出到pickle文件的格式?

How can I define the format that will be output to pickle file if casting them is not working?

推荐答案

似乎是因为我使用的是Python3,而使用Python2则获得了我想要的格式.

It seems it was because I was using Python3, with Python2 I get the format I intend to.

这篇关于如何定义将输出到pickle文件的格式(字符串,整数等)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆