Hey Tutor

Assuming i have a class bank as below .

class bank(object):
   def __init__(self, bal=0):
       self.bal = bal
   def deposit(self, amount):
       self.bal+=amount
       print self.bal

I define a method debit - which i add to the class onthefly

def debit(self, amt):
   self.bal-=amt
   print self.bal

bank.debit = debit

myacct = bank()
myacct.deposit(1000) # prints 1000
myacct.debit(99) # print 901

#I can also add an attribute owner

myaccount.owner = 'jojo'

dir(myacct) # prints [ ....'owner', 'bal', 'debit', 'deposit']


My problem is how to make the added attributes, 'owner' and 'debit'
persistent automatically

Saving the object using pickle for example does save 'owner' and 'debit'
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to