Python 用科学的方法判断函数/方法

from types import MethodType,FunctionType
def check(arg):
    """
    检查arg是方法还是函数?
    :param arg:
    :return:
    """
    # if isinstance(arg,MethodType):
    #     print('arg是一个方法')
    # elif isinstance(arg,FunctionType):
    #     print('arg是一个函数')
    # else:
    #     print('不知道是什么')

    if type(arg)== MethodType:
        print('arg是一个方法')
    elif type(arg) == FunctionType:
        print('arg是一个函数')
    else:
        print('不知道是什么')

 

posted @ 2018-08-30 21:54  中杯可乐不加冰  阅读(166)  评论(0编辑  收藏  举报