Simple account program

Ron radam2 at
Thu Mar 17 22:42:43 CET 2005

Igorati wrote:

> Hello all, I am still needing some help on this code, I have gone a bit
> further on it. Thank you for the help. I am trying to understand how to
> make the file searchable and how I am to make the deposit and withdrawl
> interact with the transaction class. 
> I need to just search the file only for the deposits and withdrawls and
> the amount in the account with a time stamp. Thank you for your
> assistance.

Hi Igorati,

In a ledger program I wrote, I setup the account classes something like 
below.  I'm not sure what you mean by searching a file.  Are you trying 
to read an already existing file?

class Transaction:
    def __init__(self): = ''
	self.amount = 0.0
         self.type = ''

class Account:
    def __init__(self, name=''): = name
         self.ledger = []

    def newtransaction(self, name, amount, type):
         transaction = Transaction() = name
         transaction.amount = amount
         transaction.type = ''

    def getbalance(self):
	balance = 0.0
	for transaction in self.ledger:
		balance += transaction.amount
         return balance

# Within your main program somewhere.
myaccount = Account( 'Savings Account')

#  get transaction data from user or file
name = 'cash'
amount = 20.0
type = 'deposite'
myaccount.newtransaction( name, amount, type)

print "%s Balance is $ %.2f" % (, myaccount.getbalance())


More information about the Python-list mailing list