关于反射

反射: 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)

原文地址:https://www.cnblogs.com/twotigers/p/7792760.html