为什么和小甲鱼一样的代码输出结果不一样......
我是跟着视频一起敲的呀......class C:
def __getattribute__(self, name):
print('getattribute')
return super().__getattribute__(name)
def __getattr__(self, name):
print('getattr')
# super().__getattr__(name)
def __setattr__(self, name, value):
print('setattr')
super().__setattr__(name, value)
def __delattr__(self, name):
print('delattr')
super().__delattr__(name)
回车后输出结果:
getattribute
getattribute
getattribute
getattribute
getattribute
c = C()
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
本帖最后由 Worromot 于 2020-4-3 10:48 编辑
https://www.bilibili.com/video/BV1MW411H79p?p=47
这是这一期视频 本帖最后由 Worromot 于 2020-4-3 11:23 编辑
定义一个实例后c = C()
就打印出很多的getattribute...... Python 用的是3.6.5,会不会和版本有关?
Worromot 发表于 2020-4-3 11:29
Python 用的是3.6.5,会不会和版本有关?
我这里什么都没有哦 应该是和 Python 的版本有关 什么也没发生>>> class C:
def __getattribute__(self, name):
print('getattribute')
return super().__getattribute__(name)
def __getattr__(self, name):
print('getattr')
# super().__getattr__(name)
def __setattr__(self, name, value):
print('setattr')
super().__setattr__(name, value)
def __delattr__(self, name):
print('delattr')
super().__delattr__(name)
>>> c=C()
>>> 小甲鱼录视频的时候还是python3.4,所以应该不是版本的问题。很奇怪,复制这段代码大家运行都没问题,我看你的描叙是输完后按回车,那么你是在shell里面输入的?建议你试试new file后录入保存再运行看看结果。 我也是,什么反应都没有-_-,不管是在new file还是在Shell。本人用的最新3.8.2版本 我用的3.8.1,视频里的所有代码(除了部分爬虫)都可以正常运行,包括这个
什么也没发生啊
>>> class C:
def __getattribute__(self, name):
print('getattribute')
return super().__getattribute__(name)
def __getattr__(self, name):
print('getattr')
# super().__getattr__(name)
def __setattr__(self, name, value):
print('setattr')
super().__setattr__(name, value)
def __delattr__(self, name):
print('delattr')
super().__delattr__(name)
>>> c = C() txxcat 发表于 2020-4-3 21:23
小甲鱼录视频的时候还是python3.4,所以应该不是版本的问题。很奇怪,复制这段代码大家运行都没问题,我看 ...
我用的是Pycharm, 试了一下用Shell就不会有问题,很奇怪
页:
[1]