def addMethod(classInstance, func, methName=None):
    """adds function as a new method to an existing class
       function should have self as first argument
    """
    meth = new.instancemethod(func, None, classInstance)
    name = methName or func.__name__
    setattr(classInstance, name, meth)
    return name
adds function as a new method to an existing class
       function should have self as first argument
    
recipes/Python/201294_Dynamic_Classes/recipe-201294.py