pluto.tools.dicts2lines¶
- pluto.tools.dicts2lines(dict_list, comment_list=None)[source]¶
Helper function to convert a list of dicts into a list of lines to use with write_table create a list of line parts to pass for write_table
- Parameters
dict_list (list) – a list of dictionaries with data to be written
comment_list (list) – a list of comment lines to prepend to the file data
Note
Returns list of lines in the format:
[ ['# comment1'], ['col1', 'col2'], ['val1', 'val2'], ... ]
Note
Dict values must be type str
Examples
Example usage:
>>> row1 = { 'a':'1', 'b':'2' } >>> row2 = { 'a':'6', 'b':7 } >>> row2 = { 'a':'6', 'b':'7' } >>> lines = dicts2lines(dict_list = [row1, row2], comment_list = comments) >>> lines ['# foo', ['a', 'b'], ['1', '2'], ['6', '7']] >>> output_path = write_table(tmpdir = '.', filename = 'output.txt', lines = lines)