Skip to content

Instantly share code, notes, and snippets.

@cocodrips
Created August 7, 2015 03:26
Show Gist options
  • Save cocodrips/282b29f91e966d39a2fd to your computer and use it in GitHub Desktop.
Save cocodrips/282b29f91e966d39a2fd to your computer and use it in GitHub Desktop.
csv.DictWriterの挙動
import csv
rows = [
{
"a": "a",
"b": "b"
}, {
"a": 1,
"b": 2
}, {
"a": 3,
"b": 4
}
]
writer = csv.DictWriter(open('dicttocsv.csv', 'w'), rows[0].keys())
for row in rows:
writer.writerow(row)
@cocodrips
Copy link
Author

Result

a,b

1,2

3,4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment