python, dynamically implement a class onthefly
Question: this is related to [python, dynamically implement a class
onthefly](http://stackoverflow.com/questions/4387847/python-dynamically-
implement-a-class-onthefly).

when i restarted my pc, couldnt get back to add comments to the post - below
is an example to explain what meant by save the class_with_the_methods_used

    
    
    class bank(object):
       def __init__(self, bal=0):
           self.bal = bal
       def deposit(self, amount):
           self.bal+=amount
           print self.bal
    
    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
    
    dir(myacct) # print [ ....'bal', 'debit', 'deposit']
    

then i used pickle and saved the object myacct

after saving, restarted my python and tried the commands below

    
    
    >>> import pickle
    >>> obj = pickle.load(open('bank.pkl'))
    >>> dir(obj) # prints [....'bal', 'deposit']
    

note that 'debit' is not among the attributes . So my problem is how to make
methods like 'debit' persistent?


Answer: Check out the `new` module (http://docs.python.org/library/new.html)

It has a lot of tools for doing things dynamically. The problem you are having
is debit is not a instance method, it is just a normal function. Methods
defined in classes are different than functions defined outside.

