Python Programming - Reading and Writing Files - Discussion

Discussion Forum : Reading and Writing Files - General Questions (Q.No. 37)
37.
How can you write a list of dictionaries to a CSV file named "data.csv"?
write_csv("data.csv", [{"key1": "value1"}, {"key2": "value2"}])
with open("data.csv", "w") as file:
    write_csv(file, [{"key1": "value1"}, {"key2": "value2"}])
csv.write("data.csv", [{"key1": "value1"}, {"key2": "value2"}])
with open("data.csv", "w") as file:
    csv.writer(file).writerow([{"key1", "value1"}, {"key2", "value2"}])
Answer: Option
Explanation:
Using a context manager to open the file and writing a list of dictionaries to a CSV file.
Discussion:
Be the first person to comment on this question !

Post your comments here:

Your comments will be displayed after verification.