python - 对象数组不可picklable

标签 python arrays class pickle spyder

我用 python 创建了一个类,如下所示:

class myClass():
    _fields_ = [1, 2]

其中 field_1 和 field_2 应该是整数。

然后我创建了一个数组,其元素属于 myClass 类,如下所示:

array = [ myClass() for i in range(5)]

当我想在变量检查器中检查array元素的值时,它给出了以下消息:

"Spyder was unable to retrieve the value of this variable from the console." 
"The error message was: Object array is not picklable"

我的问题是:如何检查数组元素的值?

最佳答案

查看以下 Spyder 相关网站:

: Downloads, bug reports and feature requests
: Discussions

<小时/>

已验证,pickle 可以处理问题中给出的对象数组
以下工作不会失败

pick_array = pickle.dumps(array)
unpick_array = pickle.loads(pick_array)

使用 Python:3.4.2 进行测试

<小时/>

要验证您的 Spyder 是否能够显示数组,请检查以下内容:

array = [ i for i in range(5)]

尝试使用 Inspector 显示变量array

如果您能够查看该变量,则这是您的 Spyder 版本处理对象数组的限制。

关于python - 对象数组不可picklable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43882605/

相关文章:

c++ - 在单个阵列上的 opencl 中处理工作组及其大小

javascript - 将字符串转换为数组 - jQuery.inArray() 不工作

c# - 将对象转换为多维字符串数组

python - 将类变量传递给类方法

html - 如何覆盖内容 div 中的 CSS 类

python - 这个 autokey Python 脚本需要并发吗?

Python - 在 for 循环中增加范围下限

objective-c - 错误: unrecognized selector sent to class

python - cx_卡住错误: 'str' object has no attribute '__cause__'

python - 如何从字符串中拆分日期和时间?