反射是通过字符串方法去映射属性和方法
    getattr():获取
    setattr():设置
    hasattr():判断是否存在

    1. 被引用模块
    2. city="beijing"
    3. country="China"
    4. def eat():
    5. print("eat")
    6. class User:
    7. def __init__(self):
    8. print("我是user")

    1.getattr()通过字符串与属性一致,获取到属性值,例如输入city,得到结果:beijing

    1. import tool
    2. var=input("var:")
    3. attr=getattr(tool,var)
    4. print(tool.city)

    2.setattr():设置属性

    1. import tool
    2. var=input("var:")
    3. def fun():
    4. print("hhh")
    5. setattr(tool,"test",fun)

    获取tool.fun(),得到结果:hhh
    3.hasattr():判断属性是否存在

    1. print(hasattr(tool,"city")) #True
    2. print(hasattr(tool,"city1")) # False