I write down the list in csv. Source Lists: enter image description here

The result is this: enter image description here

What am I doing wrong? and why only 1 list is added to the file?

def add_line_in_csv(line): with open(file_output, "w", newline="") as file: writer = csv.writer(file) writer.writerows(line) for file in list_file: my_file=open(file,"r") if file==list_file[0]: for i, line in enumerate(my_file): if i==23: text=line[:-2] text = ' '.join(text.split()) text=text.split(" ") print(text) add_line_in_csv(text) for i, line in enumerate(my_file): if i > 23: text = ' '.join(line.split()) text=text.split(" ") print(text) add_line_in_csv(text) 

    2 answers 2

    The problem is solved, it was necessary to simply create a list of lists

    • one
      Better in response to the code and bring it - gil9red

    Yes, it is necessary to wrap the list, so:

     def add_line_in_csv(line): with open(file_output, "w", newline="") as file: writer = csv.writer(file) writer.writerows([line])