0

I am working with reading and writing with csv files. When I read in the values I am performing a strip(\n\r\t) along with lstrip() and rstrip() for white spaces. When I go to write my lists, this only occurs on a windows machine, there is an extra row being written in true rows of data. Again this only happens for execution with windows machine not mac os. Here is my current write function that takes in two lists each list has had its headers and are both lists of tuples in the form(sampId,execId) appended and writes correctly other than the extra rows. Output and failed_list are both lists of tuples. Again output works correctly when performed on mac, but incorrectly on windows in which it adds an extra row of empty data between each data.

def fileWrite(output,failed_list_csv_out):
fileToWrite = open('SampleId_ExecutionId.csv','w') 
with fileToWrite:
    writer = csv.writer(fileToWrite)
    writer.writerows(output)
    writer.writerows(failed_list_csv_out)
Giorgos Myrianthous
  • 36,235
  • 20
  • 134
  • 156
  • whats your python version? – BlooB Apr 09 '18 at 16:02
  • If newline='' is not specified, newlines embedded inside quoted fields will not be interpreted correctly, and on platforms that use \r\n linendings on write an extra \r will be added. you can look at https://docs.python.org/3/library/csv.html#id3 for more info – BlooB Apr 09 '18 at 16:08
  • I am currently using python 2.7 –  Apr 09 '18 at 16:09
  • When I attempt to run the new line fileToWrite = open('SampleId_ExecutionId.csv','w', newline=' ') it lets me know that newline is not a keyword argument for this function. –  Apr 09 '18 at 16:15

0 Answers0