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)

  • 相关阅读:
    一本通1647迷路
    一本通1646GT 考试
    矩阵
    矩阵快速幂
    数学基础
    清北学堂学习经验(论颓废)
    钟皓曦第二天讲课
    P3275 [SCOI2011]糖果
    P1270 “访问”美术馆
    P2015 二叉苹果树
  • 原文地址:https://www.cnblogs.com/twotigers/p/7792760.html
Copyright © 2011-2022 走看看