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()
3 Antworten
+ 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.
0
I still don't get can you do a little run over of it
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