How to write data to a CSV file without including headers

I have a process where I need to insert a row of data into a blank CSV file and add rows of data to an existing CSV file (depending on if the CSV file is blank).

How could I add a row of data like this:

The issue I am running into is adding data without headers.

I have attempted using the write table to CSV keyword but the headers are mandatory and breaks my process every time.

The other method I attempted was csv.writer() but cannot get passed weird syntax errors.
My code for that is:

The Evaluate csv.writer(${csv_file_obj}) line is what is failing with the error:

I do not know why I am getting syntax errors here as the CSV object seems to be in the correct format.

In summary, the 2 functions I need are:

  1. Add a row of data to a blank CSV file

  2. Add a new row of data to a CSV file directly under the last row of data.

Could you share the error keyword is producing when saving to csv? I tried with code below without any issues:

*** Tasks ***
Minimal task
    @{Table_Data_name}=    Create List    Mark    John    Amy
    @{Table_Data_age}=    Create List    ${58}    ${22}    ${67}
    &{Table_Data}=    Create Dictionary
    ...    name=${Table_Data_name}
    ...    age=${Table_Data_age}
    ${table}=    Create Table    ${Table_Data}

    Write table to CSV    ${table}    test.csv    header=${false}

One way to create empty csv and add line is to use Create File keyword. Also there is library that uses csv module

You’re completely right. I should’ve seen that headers argument, thank you.

1 Like