import pickle as p acctHist = 'acctHist.data' class pettyAccount: def __init__(self, initial, open='05 Sep 07'): self.balance = initial openDate = open def deposit(self, amt, dDate='30 Oct 07'): self.balance = self.balance + amt self.date = dDate def withdraw(self, amt, wDate='30 Oct 07'): self.balance = self.balance - amt self.date = wDate def getbalance(self, gDate='30 Oct 07'): self.date = gDate return self.balance def welcome(self): prompt = input ('Welcome to the petty cash account: \ Enter 1 to Record a Deposit \ Enter 2 to Record a Withdrawal \ Enter 3 to Get the Balance') if prompt == 1: newDep = input ('Amount of deposit:') newDate = raw_input ('Date of deposit:') a.deposit(newDep) f = file(acctHist, 'w') pickFile = 'Deposit:',newDep, newDate p.dump(pickFile, f) f.close() g = file(acctHist) dTest = p.load(g) # A test so I could make sure that pickle was working print dTest print 'The new balance is $',a.getbalance(), 'on %s.' % newDate return a.welcome() elif prompt == 2: newWith = input ('Amount of withdrawal:') balance = a.getbalance() if newWith > balance: print 'Withdrawal exceeded account balance: $',balance, ' Reduce withdrawal amount.' return a.welcome() else: newDate = raw_input ('Date of withdrawal:') a.withdraw(newWith) f = file(acctHist, 'w') pickFile = 'Withdrawl:',newWith, newDate p.dump(pickFile, f) f.close() g = file(acctHist) wTest = p.load(g) print wTest # A test so I could make sure that pickle was working print 'The new balance is $',a.getbalance(), 'on %s.' % newDate return a.welcome() elif prompt == 3: today = raw_input ("Enter today's date:") print 'The current balance is $',a.getbalance(), 'on %s.' % today return a.welcome() else: print 'Thank you, goodbye' a = pettyAccount(1000) a.welcome()
transactions = dict() transactions['TRANSACTION_ID'] = ('Transaction Type:', newAmt, newDate) pickle.dump(transactions, f)
import pickle as p import operator class pettyAccount(): def __init__(self, initial=0,date='13 June 08'): self.balance = initial self.id= id self.date= date def deposit(self, amt): self.balance = self.balance + amt return self.balance def withdraw(self, amt): self.balance = self.balance - amt return self.balance def getbalance(self): f = open(acctHist, 'r') account_list=p.load(f) f.close() return (account_list) def welcome(self): #print account_list[1:0] prompt = 0 while prompt < 4: print ('Welcome to the petty cash account: \n\n\ Enter 1 to Record a Deposit \n\ Enter 2 to Record a Withdrawal \n\ Enter 3 to Get the Balance\n\ Enter 4 to Exit\n ') prompt=input('Enter option: ') if prompt == 1: newDep = input ('Amount of deposit: ') newDate = raw_input ('Date of deposit: ') newid=input('Enter a ID number for this transaction') newAmt=a.deposit(newDep) depList=dict (a=newAmt, b=newDate, c= newid) # Makeing the deposit List if id in id_list: print "This id already exists, try again!" else: id_list.append(id) break #depList[newid]=('Deposit: ', newAmt, newDate) #depList.append((newAmt, newDate, newid)) #Putting the List together f = open(acctHist, 'w') p.dump(depList,f) #Dumping the List #p.dump(a.deposit(newDep), f) #p.dump(newDate,f) f.close() print '--------------------------------------------------------' print 'The new balance is $ %s on .' % newAmt, newDate #print 'The new balance is $',a.getbalance(), 'on %s.' % newDate print '--------------------------------------------------------\n' elif prompt == 2: newWith = input ('Amount of withdrawal: ') balance = a.getbalance() if newWith > balance: print '--------------------------------------------------------' print 'Withdrawal exceeded account balance: $',balance, ' \nReduce withdrawal amount.' print '--------------------------------------------------------\n' else: newDate = raw_input ('Date of withdrawal: ') f = file(acctHist, 'w') p.dump(a.withdraw(newWith), f) p.dump(newDate,f) f.close() print '--------------------------------------------------------' print 'The new balance is $',a.getbalance(), 'on %s.' % newDate print '--------------------------------------------------------\n' elif prompt == 3: newAmt= account_list['a'] print '--------------------------------------------------------' print 'The current balance is $ %s' %newAmt print '--------------------------------------------------------\n' else: print 'Thank you, goodbye' a=pettyAccount() acctHist = 'acctHist.data' try: fin = open(acctHist, "r") account_list = p.load(fin) fin.close() print "Account database file %s has been loaded!" % acctHist print account_list welcome(account_list) except IOError: print "Cannot find account database file %s" % acctHist welcome(0)
class pettyAccount():
class pettyAccount:
{'16 Jun 2008 01:41:17': ('Deposit: ', 6, '3')}
import pickle as p import sys import time class pettyAccount: def __init__(self, initial=0,date='13 June 08'): self.balance = initial self.id= id self.date= date def deposit(self, amt): self.balance = self.balance + amt return self.balance def withdraw(self, amt): self.balance = self.balance - amt return self.balance def getbalance(self): f = open(acctHist, 'r') account_list=p.load(f) f.close() return account_list def welcome(self): prompt = 0 while prompt < 4: print ('Welcome to the petty cash account: \n\n\ Enter 1 to Record a Deposit \n\ Enter 2 to Record a Withdrawal \n\ Enter 3 to Get the Balance\n\ Enter 4 to Exit\n ') prompt=input('Enter option: ') if prompt == 1: newDep = input ('Amount of deposit: ') newDate = raw_input ('Date of deposit: ') newid=input('Enter a ID number for this transaction') newAmt=a.deposit(newDep) depList={} depList[time.strftime('%d %b %Y %H:%M:%S')]=('Deposit: ', newAmt, newDate) f = open(acctHist, 'w') p.dump(depList,f) #Dumping the List f.close() print '--------------------------------------------------------' print 'The new balance is $ %s on .' % newAmt, newDate print '--------------------------------------------------------\n' elif prompt == 2: newWith = input ('Amount of withdrawal: ') balance = a.getbalance() if newWith > balance: print '--------------------------------------------------------' print 'Withdrawal exceeded account balance: $',balance, ' \nReduce withdrawal amount.' print '--------------------------------------------------------\n' else: newDate = raw_input ('Date of withdrawal: ') f = file(acctHist, 'w') p.dump(a.withdraw(newWith), f) p.dump(newDate,f) f.close() print '--------------------------------------------------------' print 'The new balance is $',a.getbalance(), 'on %s.' % newDate print '--------------------------------------------------------\n' elif prompt == 3: print account_list newAmt= account_list[:1] print '--------------------------------------------------------' print 'The current balance is $ %s' %newAmt print '--------------------------------------------------------\n' else: print 'Thank you, goodbye' a=pettyAccount() acctHist = 'acctHist.data' try: fin = open(acctHist, "r") account_list = p.load(fin) fin.close() print "Account database file %s has been loaded!" % acctHist print account_list welcome(account_list) except IOError: print "Cannot find account database file %s" % acctHist welcome(0)
# a few examples import wx class MainFrame(wx.Frame): pass #this means this class has all the attributes of wx.Frame class Parent(object): #new style class class Child(Parent): #child has all attributes of Parent
| DaniWeb Message | |
| Cancel Changes | |