Q. Identify the error in the following code?
1. import csv
2. line [[1,2,3], [4, 5, 6]]
3. with open (path, "w", newline = '') as csv_file:
4. writer csv.writer(csv_file, delimiter = '|')
5. for line in data:
6. writer.writerow (line)
Answer :-
The give code is trying to write a nested list with writerow().
It should be replaced with writerows(), i.e., line 6 should be:-
writer.writerows (line)
Post a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )