Mercurial > hg > webcalc
annotate webcalc/formatters.py @ 1:12ac99c240ca default tip
* add documentation
* add 1..10 autostep feature
* bump version
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Wed, 10 Mar 2010 17:48:11 -0500 |
parents | 1eea6356d2e5 |
children |
rev | line source |
---|---|
0 | 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}) |