一、反射
通过字符串的形式操作对象相关的属性。(使用字符串数据类型的变量名来获取这个变量的值)
Python中的一切事物都是对象(都可以使用反射)
反射类中的变量
反射对象中的变量
反射模板中的变量
反射本文件中的变量
用反射的场景:
input
网络
文件
#hasattr def hasattr(*args, **kwargs): # real signature unknown """ Return whether the object has an attribute with the given name. This is done by calling getattr(obj, name) and catching AttributeError. """ pass #getattr def getattr(object, name, default=None): # known special case of 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. """ pass #setattr def setattr(x, y, v): # real signature unknown; restored from __doc__ """ Sets the named attribute on the given object to the specified value. setattr(x, 'y', v) is equivalent to ``x.y = v'' """ pass #delattr def delattr(x, y): # real signature unknown; restored from __doc__ """ Deletes the named attribute from the given object. delattr(x, 'y') is equivalent to ``del x.y'' """ pass