python跨平台的pickle文件? [英] Is pickle file of python cross-platform?

查看:197
本文介绍了python跨平台的pickle文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个我的小python脚本。我在Linux上保存了pickle文件,然后在windows上使用它,然后在Linux上重新使用它,但是现在这个文件在Linux上不起作用,但是它在windows上完美运行。
是python是coss平台,但是pickle文件不是。
有没有解决这个问题的方法???

解决方案

Python的pickle是完全跨平台的。 >

这可能是由于Windows和Linux之间的EOL(行尾)差异造成的。确保以二进制模式打开你的pickle文件,在写入和阅读时分别使用open()的wb和rb模式。



注意:在不同版本的Python之间传递pickle可能会造成麻烦,所以请尝试在两个平台上使用相同版本。


I have created a small python script of mine. I saved the pickle file on Linux and then used it on windows and then again used it back on Linux but now that file is not working on Linux but it is working perfectly on windows. Is is so that python is coss-platform but the pickle file is not. Is there any solution to this one???

解决方案

Python's pickle is perfectly cross-platform.

This is likely due to EOL (End-Of-Line) differences between Windows and Linux. Make sure to open your pickle files in binary mode both when writing them and when reading them, using open()'s "wb" and "rb" modes respectively.

Note: Passing pickles between different versions of Python can cause trouble, so try to have the same version on both platforms.

这篇关于python跨平台的pickle文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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