Mercurial > hg > webcalc
comparison webcalc/formatters.py @ 0:1eea6356d2e5
initial import of webcalc
author | k0s <k0scist@gmail.com> |
---|---|
date | Mon, 07 Sep 2009 15:09:03 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:1eea6356d2e5 |
---|---|
1 from StringIO import StringIO | |
2 | |
3 def CSVformat(values): | |
4 if not values: | |
5 return '' | |
6 keys = sorted([key for key in values[0].keys() | |
7 if key != 'result']) | |
8 keys.append('result') | |
9 | |
10 buffer = StringIO() | |
11 if len(keys) > 1: | |
12 print >> buffer, ','.join(keys) | |
13 for value in values: | |
14 print >> buffer, ','.join([str(value[key]) | |
15 for key in keys]) | |
16 return buffer.getvalue() | |
17 | |
18 def JSONformat(values): | |
19 import simplejson | |
20 return simplejson.dumps({'values': values}) |