从BytesIO对象中删除时如何解决EOFError?

时间:2018-10-28 13:28:11

标签: python pickle

是否可以在不创建数据的情况下腌制和取消腌制数据?在建议重复的问题中,我看不到如何解决这个问题。

  

Pickle.dump to variable

我想远程执行此操作,因此无法即时创建新文件。 所有带有酸洗和酸洗的示例都显示了pickle.dump和pickle.load的用法。 我阅读了文档,并且file参数可以是BytesIO对象,但是当我尝试使用load()函数时,我得到了。

  

EOFError:超出输入范围

有人可以给我一些如何做到这一点的例子吗? 我目前拥有的是:

a = A("some_random_string")
bio = BytesIO(b"some_bytes_data")
d = pickle.dump(a, bio)
f = pickle.Unpickler(bio).load()

负载给我上述错误。我在做什么错了?

1 个答案:

答案 0 :(得分:0)

我毕竟能够解决它。使用转储而不是转储使我成为可能。 现在以我的情况为例:

class Test
{
    void TestA()
    {
        int myVariable = 5;
    }

    void TestB()
    {
        // can't see MyVariable because it's in a different scope, and that scope isn't above the current scope
    }

    void TestC()
    {
        {
            int myOtherVariable = 5;
        }
        // can't see myOtherVariable because it was defined in a child scope of this method scope
    }
}

也许对其他人也有帮助。