[問題] Python 2.x 3.x pickle 不相容

看板Python作者 (allstar)時間13年前 (2012/09/06 10:07), 編輯推噓2(202)
留言4則, 1人參與, 最新討論串1/2 (看更多)
Python 2.7 把一個 datetime.datetime 物件打包成 bytes 傳給 Python 3.2 Python 3.2 卻沒辦法把這些 bytes 還原成 datetime.datetime 物件 錯誤訊息如下 UnicodeDecodeError: 'ascii' codec can't decode byte 0xdc in position 1: ordinal not in range(128) 試過用其他 codec,一樣噴 UnicodeDecodeError 出來 改其他 pickle protocol,也一樣噴 UnicodeDecodeError 出來 請問這是為什麼?照理說 pickle module 應該能相容才對呀? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 114.46.136.29

09/06 11:18, , 1F
pickle.load(fp, fix_imports=True)
09/06 11:18, 1F

09/06 11:26, , 2F
上面打錯,不要管上面
09/06 11:26, 2F

09/06 11:26, , 3F
應該是你dump的時候應該用dumps, python3
09/06 11:26, 3F

09/06 11:26, , 4F
好像只吃 binary buffer, 不支援 text mode
09/06 11:26, 4F
文章代碼(AID): #1GI0LGZv (Python)
文章代碼(AID): #1GI0LGZv (Python)