storing 'object'

走远了吗. 提交于 2019-12-06 16:21:41

Try the pickle module if you want to store complicated data somewhere it isn't supported by the library in question.

You can save generic Python object with Pytables:

>>> dtype = np.dtype([('Name', '|S2'), ('objValue', object)])
>>> data = np.zeros(3, dtype)
>>> file = tables.openFile('/tmp/test.h5', 'w')
>>> myobjects = file.createVLArray(file.root, 'myobjects', tables.ObjectAtom())
>>> myobjects.append(data)
>>> myobjects[0]
array([('', 0), ('', 0), ('', 0)], 
      dtype=[('Name', '|S2'), ('objValue', '|O8')])

However, this will use pickle (cPickle in fact) behind the scenes, so you won't be able to access these objects from other languages (pickle is a serialization format only supported by Python itself).

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