鱼C论坛

 找回密码
 立即注册
查看: 847|回复: 5

在零基础python的45课代码疑问

[复制链接]
发表于 2018-11-12 10:24:39 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
# -*- coding: utf-8 -*-
"""
45课代码2
属性调用属性的魔法方法
super函数是为了不影响原有的魔法方法使用,
没有继承的类默认调用object基类
"""
class C:
    def __getattribute__(self,name):
        print('getattribute')
        return super().__getattribute__(name)
    def __getattr__(self,name):
        print('getattr')
    def __setattr__(self,name,value):
        print('setattr')
        super().__setattr__(name,value)
    def __delattr__(self,name):
        print('delattr')
        super().__delattr__(name)
        
结果是:
runfile('D:/网课/属性访问.py', wdir='D:/网课')

c=C()
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
一直在打印这个,在反复调用第一个方法,可这是为什么呢?和老师代码一样,想不通。
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2018-11-12 10:27:39 | 显示全部楼层
我运行没有,你有没有哪里整错了
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2018-11-12 10:46:32 | 显示全部楼层
我用的Spyder+python3.6,把软件重新退出再开,清除所有变量运行也是不行。
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2018-11-12 10:47:14 | 显示全部楼层
塔利班 发表于 2018-11-12 10:27
我运行没有,你有没有哪里整错了


我用的Spyder+python3.6,把软件重新退出再开,清除所有变量运行也是不行,emmm
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-11-12 10:48:51 | 显示全部楼层
没用过Spyder
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2018-11-12 10:53:32 | 显示全部楼层

Anaconda3里面的,之前跟别的老师学习时候时候下的,就懒得换了可能是bug,先存疑。谢谢老师
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2026-1-3 23:32

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表