Python3 HDF5 中英文混合存储

import numpy as np
import sys
import h5py as h5
import os
print("开始")
print("系统默认编码:{}".format(sys.stdout.encoding))

def test_002():
    dt_str = h5.special_dtype(vlen=str)
    student = np.dtype([('name',dt_str), ('age', 'i1'), ('marks', 'f4')]) 
    cn_test = np.array([('abc中国123', 21, 50),('xyz', 18, 75)], dtype = student)
    print(cn_test)
    file_name="deleteme.hdf5"
    if(os.path.isfile(file_name)):
        os.remove(file_name)
    my_hdf5=h5.File(file_name,mode="a")
    my_hdf5["gp03"]=cn_test
    my_hdf5.flush()
    my_hdf5.close()

    my_hdf5 = h5.File(file_name,'r')
    print("read cn data")
    print(my_hdf5['gp03'][:])
    my_hdf5.close()


test_002()

 

上一篇:python可视化hdf5文件


下一篇:2.7 序列化(保存)tensor