Explanation: I need to take parameters from file1 and need to use in some function and then i need to take results from that function then need to write these test_name and results to a new csv i.e file2. while iam doing with below example iam getting some errors.
Readind from a CSV file1 and writing to a new CSV file2 using python
with open(inputs.csv, 'rb') as file1: #Need to read params from this file
data = list(csv.reader(file1))
with open('output.csv', 'wb') as file2: #Need to write results to this file
writer = csv.writer(file2)
for row in data:
api = row[0]
test_name =row[1]
out = funtion_call(api, test_name)
writer.writerow([test_name, out])
file1.close()
file2.close()
Output:
writer.writerow([test_name, out])
ValueError: I/O operation on closed file
pandaspandasjust for the sake of reading a csv file is overkill...with open(inputs.csv, 'rb') as file1:Maybe this should be:with open('inputs.csv', 'r') as file1:. Also why 'rb' and 'wb'? You are reading a glorified text file. Not a bytes files.