当前位置:   article > 正文

VScode+python_python官方文档 vscode

python官方文档 vscode

发现VScode在调试python的一个小问题

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)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30

当断点设置在下图所示位置的时候

debug输出
就是有两个输出
而当不设置断点的时候,或者设置断点靠后的时候
在这里插入图片描述
debug输出
有两个输出
同样的代码,在pycharm环境测试下,就没有这个问题。
暂时不清楚问题出在哪里。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Cpp五条/article/detail/603398
推荐阅读
相关标签
  

闽ICP备14008679号