h5py写入str,报错

TypeError: No conversion path for dtype: dtype(‘U8’)

h5py写入str不支持unicode编码,可以先将其转为utf-8,再写入,解决

data = [tmp.encode('utf8') for tmp in data]
hdf5.create_dataset(dataset_name, data=data, compression=compression,
                                        compression_opts=compression_opts,
                                        shuffle=shuffle)

你可能感兴趣的:(python)