def make_col(row_type, row_name, row_item, str_len): '''for strings it will always make at least 80 char or twice mac char size''' set_len = 80 if str_len: if 2 * str_len > set_len: set_len = 2 * str_len row_type[row_name] = tables.Col("CharType", set_len) else: type_matrix = { int: tables.Col("Int32", 1), float: tables.Col("Float32", 4), #Col("Int16", 1) } row_type[row_name] = type_matrix[type(row_item)]
def add_cache(fileh, cache): group_name = 'pytables_cache_v0' table_name = 'cache0' root = fileh.root group_obj = fileh.createGroup(root, group_name) cache_str = cPickle.dumps(cache, 0) cache_str = cache_str.replace('\n', chr(1)) cache_pieces = [] while cache_str: cache_part = cache_str[:8000] cache_str = cache_str[8000:] if cache_part: cache_pieces.append(cache_part) row_type = {} row_type['col_0'] = tables.Col("CharType", 8000) # table_cache = fileh.createTable(group_obj, table_name, row_type, 'H', compress=1) for piece in cache_pieces: print len(piece) table_cache.row['col_0'] = piece table_cache.row.append() table_cache.flush()