forked from DrumMachineLearning/git-practice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
36 lines (29 loc) · 983 Bytes
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import csv
import json
class TestClass(object):
def __init__(self, foo, bar, baz):
self.foo = foo
self.bar = bar
self.baz = baz
def fizz_buzz(self, digit_1, digit_2):
for i in range(1, 100):
if i % digit_1 == 0:
if i % digit_2 == 0:
print 'fizzbuzz!'
else:
print 'fizz!'
elif i % digit_2 == 0:
print 'buzz!'
else:
print i
def json_to_csv(self, json_file_path, outfile_path):
"""Convert a file containing a list of flat JSON objects to a csv.
What's a DictWriter, you say? Never heard of it!
"""
with open(json_file_path) as f:
data = json.load(f)
with open(outfile_path, 'w') as fp:
writer = csv.writer(fp)
writer.writerow(data[0].keys())
for item in data:
writer.writerow(item.values())