zoukankan      html  css  js  c++  java
  • 关于反射

    反射: hasattr,getattr,setattr,delattr

    hasattr():

    help(hasattr)

    Help on built-in function hasattr in module builtins:

     

    hasattr(obj, name, /)

    Return whether the object has an attribute with the given name.

     

    This is done by calling getattr(obj, name) and catching AttributeError

    getattr():

    Help on built-in function getattr in module builtins:

     

    getattr(...)

    getattr(object, name[, default]) -> value

     

    Get a named attribute from an object; getattr(x, 'y') is equivalent to x.y.

    When a default argument is given, it is returned when the attribute doesn't

    exist; without it, an exception is raised in that case.

    delattr()

    Help on built-in function delattr in module builtins:

     

    delattr(obj, name, /)

    Deletes the named attribute from the given object.

     

    delattr(x, 'y') is equivalent to ``del x.y''

     

     

     

    动态导入;

    import importlib

    a=importlib.import_module("a")

     

     

    重新导入: 默认状态下python只导入一次

    importlib.reload(a)

  • 相关阅读:
    [hdu1402]A * B Problem Plus(NTT)
    拦截导弹问题(Noip1999)
    删数问题(Noip1994)
    1217:棋盘问题
    随笔功能测试
    教师派8
    教师派7
    教师派6
    教师派5
    教室派4
  • 原文地址:https://www.cnblogs.com/twotigers/p/7792760.html
Copyright © 2011-2022 走看看