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

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

问题描述

我已经创建了一个我的小python脚本.我在 Linux 上保存了泡菜文件,然后在 Windows 上使用它,然后再次在 Linux 上使用它,但现在该文件在 Linux 上不起作用,但它在 Windows 上运行良好.是这样,python 是 coss-platform 但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 的 pickle 是完美的跨平台.

Python's pickle is perfectly cross-platform.

这可能是由于 Windows 和 Linux 之间的 EOL(行尾)差异所致.确保在写入和读取 pickle 文件时以二进制模式打开它们,分别使用 open() 的wb"和rb"模式.

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.

注意:在不同版本的 Python 之间传递 pickles 会导致问题,所以尽量在两个平台上使用相同的版本.

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天全站免登陆