如何在python中解码这个?

时间:2016-10-29 17:44:12

标签: python python-2.7

我试图解码这个

data = "
8002 7d71 0128 5513 6e75 6d5f 6361 7365
735f 7065 725f 6261 7463 6871 024d 1027
550b 6c61 6265 6c5f 6e61 6d65 7371 035d
7104 2855 0861 6972 706c 616e 6571 0555
0a61 7574 6f6d 6f62 696c 6571 0655 0462
6972 6471 0755 0363 6174 7108 5504 6465
6572 7109 5503 646f 6771 0a55 0466 726f
6771 0b55 0568 6f72 7365 710c 5504 7368
6970 710d 5505 7472 7563 6b71 0e65 5507
6e75 6d5f 7669 7371 0f4d 000c 752e" 

with:

''。join(chr(int(data [i:i + 2],16))for i in range(0,len(data),2))

结果是:

\x80\x02}q\x01(U\x13num_cases_per_batchq\x02M\x10'U\x0blabel_namesq\x03]q\x04(U\x08airplaneq\x05U\nautomobileq\x06U\x04birdq\x07U\x03catq\x08U\x04deerq\tU\x03dogq\nU\x04frogq\x0bU\x05horseq\x0cU\x04shipq\rU\x05truckq\x0eeU\x07num_visq\x0fM\x00\x0cu."

这是cifar 10数据库的类名,我理解像

这样的名字
airplane
automobile
bird
cat
deer
dog
frog
horse
ship
truck

但我不知道

的含义
\x80\x02}q\x01(U\x13
 q\x02M\x10'U\x0b...
 and so on...

我需要以这种格式转换自己的单词,但我不理解“单词”

谢谢!

1 个答案:

答案 0 :(得分:4)

它的泡菜:

>>> import pickle
>>> print(pickle.loads('''\x80\x02}q\x01(U\x13num_cases_per_batchq\x02M\x10'U\x0blabel_namesq\x03]q\x04(U\x08airplaneq\x05U\nautomobileq\x06U\x04birdq\x07U\x03catq\x08U\x04deerq\tU\x03dogq\nU\x04frogq\x0bU\x05horseq\x0cU\x04shipq\rU\x05truckq\x0eeU\x07num_visq\x0fM\x00\x0cu."'''))
{'num_cases_per_batch': 10000, 'label_names': ['airplane', 'automobile', 'bird', 'cat', 'deer', 'dog', 'frog', 'horse', 'ship', 'truck'], 'num_vis': 3072}