def method_to_func(f):
    """
    Converts a bound method to an unbound function.
    """
    try:
        return f.im_func
    except AttributeError: #Python 3
        try:
            return f.__func__
        except AttributeError: # not a method
            return f