Last active
June 13, 2018 05:03
-
-
Save shiro01/abb9a5a3088ebbf45f29b93ccb534fc7 to your computer and use it in GitHub Desktop.
dict data save to csv file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import csv | |
data = [ | |
{ | |
"deta1":"111" | |
,"data2":"222" | |
}, | |
{ | |
"deta1":"333" | |
,"data2":"444" | |
} | |
] | |
# save to csv file | |
header = data[0].keys() | |
filename = "/tmp/test.csv" | |
with open(filename ,"w", newline="", encoding='utf-8') as f: | |
writer = csv.DictWriter(f, fieldnames=header) | |
writer.writeheader() | |
[writer.writerow(row) for row in data] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment