Object array is not picklable

拈花ヽ惹草 提交于 2019-12-24 10:03:59

问题


I made a class in python like the following:

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

where field_1 & field_2 are supposed to be integers.

Then I created an array that its elements are of the class myClass as following:

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

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?


回答1:


Check out the following Spyder related sites:

: Downloads, bug reports and feature requests
: Discussions


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)

Tested with Python:3.4.2


To verify your Spyder is able to show a array at all, check the following:

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

Try to show the variable array with Inspector.

If you are able to view the variable, it's a limitation from your Spyder Version to handle object array.



来源:https://stackoverflow.com/questions/43882605/object-array-is-not-picklable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!