[Tutor] Setting up a database

Liam Clarke cyresse at gmail.com
Wed Mar 2 01:40:31 CET 2005

While we generally don't get too specific with assignments and/or homework - 

For a traditional database, you'd have to go the mySQL route. A
dictionary is good, but for only one discreet key. That said, you
could do it with objects like this -

dictOfTransactionObjects = {}

class CashTransaction:
         def __init__(self, amount, depOrWith):
               self.transactionType = depOrWith
#...do various things which get the various values dateStamp, amount, transType

dictOfTransactionObjects[dateStamp] = CashTransaction(amount, transType)

So, now your dictionary will be {'01/05/2004-22:00:00' : <instance of

And you could search either by the dictionary key which is acting like
a primary key,  (the timestamp) or like this -

isWith = []
for  (key, item) in dictOfTransactionObjects.items():
       if item.transactionType == 'Withdrawal':

And isWith becomes a list of primary keys of withdrawals.
That said, I would use SQL queries instead, it's a lot more
straightforward, you'll end up reinventing several wheels this way.


Liam Clarke

On Tue, 01 Mar 2005 18:22:08 -0500, James O. Sweeney
<james.sweeney at ieee.org> wrote:
> Hello, 
> I have an assignment that entails entering cash transactions as records. The
> significant record fields are a date/time stamp, the amount, and whether the
> transaction is a deposit or withdrawal. My question is about setting up the
> database file. In Python there is a dictionary function but it looks as if
> only one value can be assigned to the key (I intend to make the key the
> timestamp). The file has to be searchable so that reports can be pulled
> regarding amount, date range, etc. – the usual things one would do with a
> database. I can't figure if I can make a query on a multi-field record in
> Python without engaging a dependency such a storing the record in a mySQL
> database and querying it from Python. I'm having real burnout with this and
> would appreciate a point in the right direction. 
> Much Thanks, 
> James 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor

'There is only one basic human right, and that is to do as you damn well please.
And with it comes the only basic human duty, to take the consequences.

More information about the Tutor mailing list