对象数组不可腌制 [英] Object array is not picklable
问题描述
我在python中制作了一个类似于以下内容的类:
I made a class in python like the following:
class myClass():
_fields_ = [1, 2]
其中field_1&字段_2应该是整数.
where field_1 & field_2 are supposed to be integers.
然后我创建了一个数组,该数组的元素属于myClass
类,如下所示:
Then I created an array that its elements are of the class myClass
as following:
array = [ myClass() for i in range(5)]
当我想在变量检查器中检查array
元素的值时,它会显示以下消息:
When I wanted to check the values of the elements of array
in the variable inspector, it gives my the following message:
"Spyder was unable to retrieve the value of this variable from the console."
"The error message was: Object array is not picklable"
我的问题是:如何检查数组元素的值?
My question is: How can I check the values of the elements of the array?
推荐答案
查看以下与 Spyder 相关的站点:
Check out the following Spyder related sites:
: Downloads, bug reports and feature requests
: Discussions
已验证,pickle
可以处理问题中给出的object array
.
以下内容可以正常运行.
Verifyed, pickle
can handle object array
given in Question.
The following works without failure.
pick_array = pickle.dumps(array)
unpick_array = pickle.loads(pick_array)
使用Python:3.4.2
Tested with Python:3.4.2
要验证您的 Spyder 能否完全显示array
,请检查以下内容:
To verify your Spyder is able to show a array
at all, check the following:
array = [ i for i in range(5)]
尝试使用Inspector显示变量array
.
Try to show the variable array
with Inspector.
如果您能够查看该变量,则是Spyder版本处理对象数组的限制.
If you are able to view the variable, it's a limitation from your Spyder Version to handle object array.
这篇关于对象数组不可腌制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!