def modify_class(cls,name=None,default=noop):
    """
    Modify an class attribute/method.
    
    This decorator factory returns a decorator which modifies on the fly (i.e. monkeypatches)
    the class "cls" by adding or replacing the attribute (typically method) indicated by the
    variable "name" (which defaults to the name of the wrapper function) with the result 
    of the decorated function, to which is passed as only parameter the old attribute with the same name
    (or a default value, by default a dummy function, if none exists).
    
    @param cls: the class to modify
    @param name: the name of the attribute/method to modify in the class 
    (defaults to the decorated function name)
    @param default: the value which is passed to the decorated function if there is no
    attribute named 'name' in 'cls' (defaults to a dummy function)
    @return: a decorator  
    """
    def wrapper(fn):
        """
        The actual decorator returned by modify_class, which actually modifies the class.
        
        @param fn: the function to decorate
        @return: the argument function.
        """
        if name is None:
            name_ = fn.__name__
        else:
            name_ = name
        original_method = getattr(cls,name_,default)
        new_method = fn(original_method)
        setattr(cls,name_,new_method)
        return fn
    return wrapper

    Modify an class attribute/method.
    
    This decorator factory returns a decorator which modifies on the fly (i.e. monkeypatches)
    the class "cls" by adding or replacing the attribute (typically method) indicated by the
    variable "name" (which defaults to the name of the wrapper function) with the result 
    of the decorated function, to which is passed as only parameter the old attribute with the same name
    (or a default value, by default a dummy function, if none exists).
    
    @param cls: the class to modify
    @param name: the name of the attribute/method to modify in the class 
    (defaults to the decorated function name)
    @param default: the value which is passed to the decorated function if there is no
    attribute named 'name' in 'cls' (defaults to a dummy function)
    @return: a decorator  
    
recipes/Python/577628_Dynamically_modifying_class_attributes_at/recipe-577628.py