【问题标题】:nested pytables嵌套的 pytables
【发布时间】:2012-10-24 21:20:11
【问题描述】:

假设您将字典传递给 pytable 构造函数:

h5f.createTable('/','table',{'col1':Float64Col(pos=0),'col2':StringCol(16,pos=1)})

我有以下三个关于嵌套pytables的初学者问题:

1) 如何使用字典描述符来创建嵌套的 pytable? 2)如何为嵌套列分配位置? 如果顶级列的位置为 pos=1,您是否从 0 开始对其子列进行编号? 3)如何将行分配给嵌套列?

感谢您的帮助!

【问题讨论】:

    标签: pytables


    【解决方案1】:

    我一直在使用 python type() 动态创建 pytables 描述。这至少应该能让你继续前进......

    from tables import *
    
    h5_file = openFile('test_nested_table.h5', 'w')
    
    nested_table_fields = {}
    nested_table_fields['x'] = Float64Col(dflt=1, pos=0)
    nested_table = type('nested_table', (IsDescription,), nested_table_fields)
    
    main_table_fields = {}
    main_table_fields['y'] = Float64Col(dflt=1, pos=0)
    main_table_fields['nested_table'] = nested_table
    main_table = type('main_table', (IsDescription,), main_table_fields)
    
    h5_table = h5_file.createTable('/', 'nested_table_example', main_table)
    print repr(h5_table)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-12-17
      • 1970-01-01
      • 2013-05-16
      • 1970-01-01
      • 1970-01-01
      • 2018-11-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多