Created
June 26, 2015 02:16
-
-
Save d30jeff/c45174f99bde6f4e6a7f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
csv_data = "" | |
for x in json_format: | |
csv_data += str(x['name']) + str(x['flowrate']) + str(x['temperature']) + str(x['power']) + str(x['log_time']) + str(x['created_on']) |
Great answer
if you don't hate the builtins;
items = ['name', 'flowrate', 'temperature', 'power', 'log_time', 'created_on']
csv_data = reduce(add, map(lambda x: reduce(add, map(str, map(x.get, items))), json_format))
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This could be done somewhat neater. From the variable names I think you're looking for CSV data, but let's first make a list of strings:
Then if it is CSV output that you want, you want a CSV writer. This code writes your data to stdout in CSV format: