Hi I am using this method to write a csv file from a csv file which is a hashed code but i only receive the last row in output, how can i add each row to the previous one?
import hashlib
import csv
d = dict()
result = ()
for i in range(0 , 9999) :
n = hashlib.sha256(str(i).encode())
d[n.hexdigest()] = str(i)
with open('/Users/MJ-Mac/Desktop/karname.txt') as f:
file = csv.reader(f)
for row in file :
a = row[0]
b = d[row[1]]
result = (a , b)
with open('/Users/MJ-Mac/Desktop/result3.txt', 'w') as f2:
file2 = csv.writer(f2)
file2.writerow(result)
csv.writerwirks fine with'w'as long as there is only one instance ofcsv.writer. Changing the code so there's just one instance is more effective