赞
踩
VScode版本是1.30.2,python版本是3.7.1
class Animal(object): run = True class Dog(Animal): fly = False def __init__(self,age): self.age = age def __getattr__(self, name): print("calling __getattr__\n") if name == 'adult': return True if self.age >= 2 else False else: raise AttributeError def __setattr__(self, name, value): print ("calling __setattr__") super(Dog, self).__setattr__(name, value) def __delattr__(self, name): print ("calling __delattr__") super(Dog, self).__delattr__(name) # 创建实例对象dog dog = Dog(1) # 检查一下dog和Dog的__dict__ print(dog.__dict__) print(Dog.__dict__) print(dog.age) # 获取dog的adult属性。 # 由于__getattribute__没有找到相应的属性,所以调用__getattr__。 print(dog.adult) # 调用一个不存在的属性name,__getattr__捕获AttributeError错误 # print(dog.name)
当断点设置在下图所示位置的时候
debug输出
而当不设置断点的时候,或者设置断点靠后的时候
debug输出
同样的代码,在pycharm环境测试下,就没有这个问题。
暂时不清楚问题出在哪里。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。