con, cur = get_cursor()
cur.execute(create_temp_table, {"idbde" : idbde})
cur.execute(display_all)
- l = cur.fetchall()
+ all = cur.fetchall()
+ cur.execute(display_sum)
+ tot = cur.fetchall()[0]
+ return (all, tot)
+
+def display_depenses(all, tot):
+ """Pretty-printing des résultats."""
print "annee\tdepenses\tgains"
- for li in l:
+ for li in all:
li = [int(li[0]), li[1], li[2]]
print "%s\t%s\t\t%s" % tuple(li)
- cur.execute(display_sum)
- l = cur.fetchall()
print "\nTotal :\n\tdepenses\tgains"
- print "\t%s\t\t%s" % tuple(l[0])
+ print "\t%s\t\t%s" % tuple(tot)
if __name__ == "__main__":
idbde = int(sys.argv[1])
- get_depenses(idbde)
+ all, tot = get_depenses(idbde)
+ display_depenses(all, tot)