作者hsnu114444 (littleq0903)
看板Python
标题Re: [问题] Python 2.x 3.x pickle 不相容
时间Thu Sep 6 11:49:55 2012
刚刚试了一下还真的不行,查了一下发现有这个 issue:
http://bugs.python.org/issue6784
看起来是 solved 但还没 merge 进去,因为 test 还没写。
如果只要带 datetime 的话,可以用 timestamp 的方式带字串,应该可行
具体用法如下:
import time, datetime
datetime.datetime.fromtimestamp(time.time())
time.time() 会传出一个 timestamp 的字串
datetime.datetime.fromtimestamp 会吃 timestamp 的字串再转成 datetime 物件
希望对你有帮助:)
※ 引述《os653 (allstar)》之铭言:
: 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: 140.112.4.191
1F:推 os653:看来是pickle的问题,遗憾的是我需要的不只是datetime... 09/06 15:11
2F:→ os653:其实只要能让 Python2 object 转换成 Python3 object 就行 09/06 15:13
3F:→ os653:不管怎样,还是多谢您了 09/06 15:14
4F:推 keitheis:谢谢助教大大 09/25 14:23