+# Returns integer x formatted in decimal with thousands set off by commas.
+def commafy(x):
+ return _commafy("%d" % x)
+def _commafy(s):
+ if s.startswith('-'):
+ return '-' + _commafy(s[1:])
+ elif len(s) <= 3:
+ return s
+ else:
+ return _commafy(s[:-3]) + ',' + _commafy(s[-3:])
+