Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/354.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 蟒蛇泡菜坏了?_Python_Python 3.x_Typeerror_Pickle_Deque - Fatal编程技术网

Python 蟒蛇泡菜坏了?

Python 蟒蛇泡菜坏了?,python,python-3.x,typeerror,pickle,deque,Python,Python 3.x,Typeerror,Pickle,Deque,当我尝试pickle和unpickle自定义类的对象时,我收到了一个奇怪的错误 from collections import deque class Buffer(deque): def __init__(self, maxlen=cf.BUFFER_SIZE): super().__init__(maxlen=maxlen) 类包含一些附加功能,但即使如此简单的实现也会产生错误 复制错误的代码: pickle.loads(pickle.dumps(Buffer())

当我尝试pickle和unpickle自定义类的对象时,我收到了一个奇怪的错误

from collections import deque
class Buffer(deque):
    def __init__(self, maxlen=cf.BUFFER_SIZE):
        super().__init__(maxlen=maxlen)
类包含一些附加功能,但即使如此简单的实现也会产生错误

复制错误的代码:

pickle.loads(pickle.dumps(Buffer()))
错误:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-60-70ac6b3f6f8f> in <module>
----> 1 pickle.loads(pickle.dumps(Buffer(), fix_imports=False))

TypeError: __init__() takes from 1 to 2 positional arguments but 3 were given
---------------------------------------------------------------------------
TypeError回溯(最近一次调用上次)
在里面
---->1 pickle.load(pickle.dumps(Buffer(),fix_imports=False))
TypeError:\uuuu init\uuuuu()接受1到2个位置参数,但给出了3个

Python版本:3.7.5(默认值,2019年10月25日,15:51:11)[GCC 7.3.0]

pickle
尝试重新构造
Buffer
对象时,它将被传递基础
deque
所采用的所有参数,这些参数既是iterable,也是maxlen值。您还需要接受
iterable
参数,并在
super()调用中传递它。想想看——如果无法为缓冲区指定任何内容,你怎么可能恢复一个pickle
缓冲区呢?