def attachmethod(target):
    '''
    Reference: https://blog.tonyseek.com/post/open-class-in-python/

    class Spam(object):
        pass

    @attach_method(Spam)
    def egg1(self, name):
        print((self, name))

    spam1 = Spam()
    # OpenClass 加入的方法 egg1 可用
    spam1.egg1("Test1")
    # 输出Test1
    '''
    if isinstance(target, type):
        def decorator(func):
            setattr(target, func.__name__, func)
    else:
        def decorator(func):
            setattr(target, func.__name__, partial(func, target))
    return decorator
Reference: https://blog.tonyseek.com/post/open-class-in-python/

    class Spam(object):
        pass

    @attach_method(Spam)
    def egg1(self, name):
        print((self, name))

    spam1 = Spam()
    # OpenClass 加入的方法 egg1 可用
    spam1.egg1("Test1")
    # 输出Test1