zoukankan      html  css  js  c++  java
  • python inspect 模块 和 types 模块 判断是否是方法,模块,函数等内置特殊属性

    python inspect 模块 和 types 模块 判断是否是方法,模块,函数等内置特殊属性

    inspect

    import inspect

    def fun():

        pass

    inspect.ismodule(fun)

    inspect.isclass(fun)

    inspect.ismethod(fun)

    for attr in dir(inspect):

        print(attr)

    输出:

    isabstract
    isasyncgen
    isasyncgenfunction
    isawaitable
    isbuiltin
    isclass
    iscode
    iscoroutine
    iscoroutinefunction
    isdatadescriptor
    isframe
    isfunction
    isgenerator
    isgeneratorfunction
    isgetsetdescriptor
    ismemberdescriptor
    ismethod
    ismethoddescriptor
    ismodule
    isroutine
    istraceback
    itertools

    ...

    types

    import types

    def fun():

        pass

    isinstance(fun, types.FunctionType)

    for t in dir(types):

        print(t)

    输出:

    AsyncGeneratorType
    BuiltinFunctionType
    BuiltinMethodType
    ClassMethodDescriptorType
    CodeType
    CoroutineType
    DynamicClassAttribute
    FrameType
    FunctionType
    GeneratorType
    GetSetDescriptorType
    LambdaType
    MappingProxyType
    MemberDescriptorType
    MethodDescriptorType
    MethodType
    MethodWrapperType
    ModuleType
    SimpleNamespace
    TracebackType
    WrapperDescriptorType
    ...

  • 相关阅读:
    HDU-2602-Bone Collector
    HDU-1171-Big Event in HDU
    javascript概要
    核桃的数量
    P3372 【模板】线段树 1
    P3373 【模板】线段树 2
    拿糖果
    第二点五个不高兴的小明
    树的直径
    1240. 完全二叉树的权值
  • 原文地址:https://www.cnblogs.com/ibingshan/p/10244178.html
Copyright © 2011-2022 走看看