简体   繁体   English

如何使用Python 2.7正确解开使用2.5腌制的内容?

[英]How to correctly unpickle with Python 2.7 what has been pickled using 2.5?

I am migrating a web app from Python 2.5 runtime to Python 2.7. 我正在将Web应用程序从Python 2.5运行时迁移到Python 2.7。 My app stores pickled data into the database, and when unpickling what I stored I have some issues with long integers: 我的应用程序将腌制后的数据存储到数据库中,而当解开存储的数据时,长整数存在一些问题:

An int like 100003087328067, pickled using Python 2.5, gets unpickled to 2147483647 (which is 2^31-1) under Python 2.7. 像100003087328067这样的int使用Python 2.5进行了腌制,在Python 2.7下被腌制为2147483647(即2 ^ 31-1)。

How to retrieve the right value? 如何获取正确的值?

Can there be other issues? 还会有其他问题吗? With str encoding for instance? 以str编码为例? (I found this but it's with python 3: Unpicking data pickled in Python 2.5, in Python 3.1 then uncompressing with zlib ) (我发现了这一点,但它与python 3一起使用: 取消选择在Python 2.5,Python 3.1中腌制的数据,然后使用zlib解压缩

More about my context: I am migrating a Google App Engine app, and I stored my data using a custom db.Property that acts a bit like the NDB PickleProperty. 关于我的上下文的更多信息:我正在迁移Google App Engine应用程序,并使用自定义db.Property存储了数据,该自定义db.Property的行为有点类似于NDB PickleProperty。

I would suggest a two stage setup: 我建议分两个阶段进行设置:

Write a Python 2.5 script to unpickle the current values, store them with a common format like JSON, then read it back into a Python 2.7 app. 编写Python 2.5脚本以释放当前值,并以JSON之类的通用格式存储它们,然后将其读回Python 2.7应用程序。

Ideally, continue to use a format like JSON rather than pickling, so that it isn't dependant on the platform in the future. 理想情况下,继续使用JSON之类的格式而不是酸洗,这样将来它就不再依赖于平台了。 Even better, store the data in the database as properly normalised data, so it can be used even more easily. 更好的是,将数据作为适当规范化的数据存储在数据库中,因此可以更轻松地使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM