0

How do I append or write the result of the loops to the file or another file

import csv with open('text1.csv', 'r+') as File: file=csv.reader(File) for e, b in file: print('name: ', e) print('age', b) print()

16th Jul 2020, 11:52 PM
Ajisegiri Sunday
Ajisegiri Sunday - avatar
3 odpowiedzi
+ 2
See as your code read the content line by line in a loop . At the same time open the another file like a = open("file name","w") and the file with be automatically created. So as long your loop goes just keep appending the result In the opened file whose name is a.
17th Jul 2020, 12:05 AM
Ayush Kumar
Ayush Kumar - avatar
0
I still don't get can you do a little run over of it
17th Jul 2020, 12:18 AM
Ajisegiri Sunday
Ajisegiri Sunday - avatar
0
To add to the first answer: with open("<filename>", "a") as csv_file: .... the "a" in the statememt means to open a file to append. if file doesnt exist, makes a new one, else appends to file. "w" will make a new file no matter what. Then make a writer like you made a reader, and use that to write to a file
17th Jul 2020, 1:22 AM
Slick
Slick - avatar