# -*- coding: utf-8 -*-
# @Time : 2021/8/1 18:01
# @Author : zy7y
# @Gitee : https://gitee.com/zy7y
# @File : getattr.py
# @Project : PythonBooks
"""
__getattr__: 获取属性,当找不到属性时 会调用这个方法
__getattribute__: 获取属性时,都会调用这个方法,其内部其实还是调用了__getattr__
"""
class User:
def __init__(self, age):
self.age = age
def __getattr__(self, item):
print(item, "__getattr__")
def __getattribute__(self, item):
print(item, "__getattribute__")
if __name__ == '__main__':
print(User(18).name)
print(User(18).age)