[Tutor] sqlite3 format data from tables
David
david at abbottdavid.com
Sun May 24 01:15:55 CEST 2009
Martin Walsh wrote:
> 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 at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
Thanks very nice,
Your transaction History is:
Food -100.00
Deposit -200.00
Deposit 500.00
Python Book -50.00
Gift 300.00
Also thank you Alan for your tips :)
>>
>> def report_transactions(self):
>> return self.database.get_transactions()
>
> Unless you intend doing something useful this function
> is just an extra later of processing!
I got a kick out of it, helped me understand how the different
function's and the classes work together, thats all, I found most of the
code on the web and just patched it together to be honest :)
>> Can I use the numbers 1,2,3,4 as a way to return the history?
>
> I don;t really understand what you mean by this bit?
>
>
Here is the data as it is returned from sqlite;
Your transaction History is: [(1, u'Food', -100), (2, u'Deposit', -200),
(3, u'Deposit', 500), (4, u'Python Book', -50)]
I was wondering if the numbers could be used to return the contents of
the tuple's.
Sometimes it is hard to ask a good question when I don't have a clue,
thanks for your patience.
--
Powered by Gentoo GNU/Linux
http://linuxcrazy.com
More information about the Tutor
mailing list