Skip to content

Instantly share code, notes, and snippets.

@shiro01
Last active June 13, 2018 05:03
Show Gist options
  • Save shiro01/abb9a5a3088ebbf45f29b93ccb534fc7 to your computer and use it in GitHub Desktop.
Save shiro01/abb9a5a3088ebbf45f29b93ccb534fc7 to your computer and use it in GitHub Desktop.
dict data save to csv file
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