David wrote: > David wrote: >> I have a budget program I am using to learn from. >> http://linuxcrazy.pastebin.com/f3b301daf >> >> I can not figure out how to get the transaction details to return so >> that it looks nice. It returns like this now. >> >> Your transaction History is: [(1, u'Food', -100), (2, u'Deposit', >> -200), (3, u'Deposit', 500), (4, u'Python Book', -50)] >> >> Here is how it gets to that point; >> >> def get_transactions(self): >> ct=self.connection.cursor() >> ct.execute("select * from transact;") >> return ct.fetchall() >> >> def report_transactions(self): >> return self.database.get_transactions() >> >> def display_transactions(self): >> print "Your transaction History is:",self.bl.report_transactions() >> >> self.menu[5]=("Transaction History",self.display_transactions) >> >> Can I use the numbers 1,2,3,4 as a way to return the history? >> >> Thanks, I hope I explained it correctly :) >> -david > Ok this seems to work OK; > def display_transactions(self): > transactions = self.bl.report_transactions() > for data in transactions: > print "Transaction History: ", data[-2], data[-1] > >
It would be helpful if you showed the output you expect. Here is another option ... def display_transactions(self): transactions = self.bl.report_transactions() print "Your transaction History is:" for n, k, v in transactions: print ' %-15s %10.2f' % (k, v) HTH, Marty _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor