\(\newcommand{\B}[1]{ {\bf #1} }\) \(\newcommand{\R}[1]{ {\rm #1} }\)
csv.write_table¶
View page sourceCreate A CSV File from a Table¶
Prototype¶
# at_cascade.csv.write_table
def write_table(
file_name = None,
table = None,
columns = None,
) :
assert type(file_name) == str
assert type(table) == list
assert type(columns) == list or columns == None
if columns == None :
columns = table[0].keys()
table¶
This must be a list of dict.
columns¶
This is a list of str specifying the keys in the table dictionary
that are written to the file.
If this argument is None ,
table [0].keys() is used as its default value.
If csv.read_table returns am empty table,
csv.get_header can be used to determine the column names.
file_name¶
is a str with the name of the CSV file.
Upon return, this file has len( table ) + 1 lines,
len( columns ) columns, with the following values
columns[0] |
columns[1] |
columns[2] |
… |
table[0][ columns[0] ] |
table[0][ columns[1] ] |
table[0][ columns[2] ] |
… |
table[1][ columns[0] ] |
table[1][ columns[1] ] |
table[1][ columns[2] ] |
… |
: |
: |
: |
… |