说明:我需要从file1中获取参数,并且需要在某些函数中使用,然后我需要从该函数获取结果,然后需要写入这些test_name和结果到一个新的CSV文件2。而我下面的例子iam做了一些错误。从CSV文件中读取并在Python中写入新的CSV文件
Readind从一个CSV文件1,并使用Python写一个新的CSV文件2
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()
输出:
writer.writerow([test_name, out])
ValueError: I/O operation on closed file
请在你的问题中粘贴确切的错误信息和回溯,“一些错误”不是一个非常有用的信息! –
只是使用'pandas' – danche
安装'pandas'只是为了读取一个csv文件是矫枉过正... –