腾讯云
开发者社区
文档
建议反馈
控制台
首页
学习
活动
专区
工具
TVP
最新优惠活动
文章/答案/技术大牛
搜索
搜索
关闭
发布
登录/注册
精选内容/技术社群/优惠产品,
尽在小程序
立即前往
文章
问答
(9999+)
视频
沙龙
1
回答
使用
__
getattribute__
获取
方法
的
名称
,
没有
类型
错误
python-3.x
我正在尝试
使用
__
getattribute__
打印
方法
的
名称
但是我每次调用该
方法
时都会得到typeerror,并且该
方法
不会被执行,有
没有
办法摆脱
类型
错误
并执行该
方法
呢?Person(object): super() print(1) def __
getatt
浏览 10
提问于2019-10-03
得票数 1
回答已采纳
1
回答
__
getattribute__
什么时候不参与属性查找?
python
、
attributes
def __
getattribute__
(self, att):__
getattribute__
的
实现显然失败了所有的查找。我
的
问题: 不受__
getattri
浏览 3
提问于2016-07-07
得票数 4
回答已采纳
1
回答
返回类变量属性时
的
python __
getattribute__
RecursionError
python
、
python-3.x
、
recursion
、
getattr
、
getattribute
为什么Foo2会导致无限递归调用__
getattribute__
中
的
类变量
的
getattr,而Foo在__getattr__中可以很好地进行同样
的
调用?对如何让Foo2正常工作有什么建议吗?__foo = Foobar() try: if __name__ == '__ma
浏览 20
提问于2020-04-25
得票数 1
回答已采纳
1
回答
Python3 __
getattribute__
与点访问行为
python
、
python-3.x
我在python
的
对象属性查找(这里:)上读了一点。__getattribute__('foobar') # raises AttributeError第二个为什么会引发属性
错误
?显然,答案是a.foobar
的
逻辑与a.__getattribute("foobar")
的
逻辑不同。根据:a.foobar调用a.-__getattr__('foobar') 因此,这篇文章似乎在他们
浏览 1
提问于2016-08-19
得票数 2
回答已采纳
1
回答
__getattribute__调用描述符(
类型
(Self),attr)不起作用
python
、
descriptor
、
getattribute
、
python-3.9
class C: self.arg1 = name c.arg1显然,如果我将__
getattribute__
内部
的
代码更改为以下备选方案: typ
浏览 4
提问于2020-12-21
得票数 1
回答已采纳
2
回答
带条件
的
链式类
方法
python
、
python-3.x
假设我有以下简化
的
类: def __init__(self, input_1): # Do something如果我想按顺序调用这些
方法
instance.method_1() instance.method_2()
浏览 2
提问于2022-07-07
得票数 1
2
回答
在定义__
getattribute__
方法
时,出现“”NoneType“”对象不支持项赋值
的
情况
python
、
python-3.x
我是Python
的
新手。最近,我一直在读关于Python类
的
内置
方法
的
文章。__dict__[key] = value pass setattr(T, 'xx', 33)当我运行此脚本时,我收到<e
浏览 0
提问于2016-03-28
得票数 1
2
回答
如何正确地覆盖Python中新样式类上
的
__setattr__和__
getattribute__
?
python
、
python-3.x
、
inheritance
、
python-2.x
、
setattr
我想覆盖我
的
Python类
的
__
getattribute__
和__setattr__
方法
。我
的
用例是一个常见
的
用例:我有几个想要处理
的
特殊
名称
,并且我想要任何其他
名称
的
默认行为。对于__
getattribute__
,似乎只需引发AttributeError就可以请求默认行为。但是,如何在__setattr__中实现相同
的
功能呢?下面是一个简单
的
例子,实现一个带有不
浏览 0
提问于2011-08-12
得票数 44
回答已采纳
3
回答
它在Python文档中为
方法
名加上前缀吗?
python
、
python-3.x
例如,我一直在读到:在文档中,它
的
定义头被写成:这是指向
的
链接。更让人困惑
的
是,跑步:引发
错误
:更新, 我还考虑了表示类
的
实例
的
可能性
浏览 11
提问于2021-12-12
得票数 1
2
回答
为什么__
getattribute__
失败了: TypeError:'NoneType‘对象不可调用
python
、
typeerror
、
getattribute
这是我在这里
的
第一个问题,也是我在Python中
的
第一个项目。我试图存储一个名为Ip500Device
的
类
的
实例 def __init__(self, shortMac,__nbOfObjects=0 def __
getattribute__
(self, att):
浏览 0
提问于2016-12-29
得票数 2
回答已采纳
4
回答
有
没有
办法创建一个不污染其实例
的
属性命名空间
的
Python类
方法
?
python
、
python-2.7
、
oop
我想提供一个可以在Python2.7类对象上
使用
的
方法
,但不会污染其实例
的
属性命名空间。有什么
方法
可以做到这一点吗? >>> class Foo(object): ...
浏览 47
提问于2017-01-25
得票数 4
回答已采纳
2
回答
检测__
getattribute__
调用是否为hasattr所致
python
、
getattribute
、
hasattr
我正在为一个类重新实现__
getattribute__
。我知道: __
getattribute__
实现被鼓励尽可能小,尽可能简单。根据调用
的
方式/原因,__
getattribute__
实现
的
行为不同被认
浏览 3
提问于2018-10-23
得票数 1
回答已采纳
1
回答
Python "__setattr__“和"__
getattribute__
”混淆
python
、
python-internals
# interceptor to allows me to define rules for whenever an attribute's value is accessedprint(spam.b)但是上面的代码
没有
打印任何东西。我在中读到了这些
方法
浏览 1
提问于2019-02-04
得票数 0
回答已采纳
1
回答
Python:遍历用户定义
的
Oracle PL/SQL
类型
python
、
oracle
、
cx-oracle
我正在尝试
使用
完全通过api访问
的
Oracle系统(不直接访问表)。Oracle端是这样构建
的
: authid definer type Python_test_rec is,end Chb_pythontest;
使用
下面的我还
没有
找到动态遍历它
浏览 6
提问于2021-10-05
得票数 0
6
回答
如何在
没有
无限递归
错误
的
情况下实现__
getattribute__
?
python
、
class
、
getattr
我想重写对类中一个变量
的
访问,但正常返回所有其他变量。如何
使用
__
getattribute__
实现这一点class D(object): self.test=20 def __
getattribute__
(self,name): if name=='
浏览 1
提问于2008-12-16
得票数 119
回答已采纳
1
回答
在
使用
时,我可以修补要抛出
的
任意对象实例吗?
python
动机 单例
的
新实例可以是相同
的
或不同
的
类型
。__
getattribute__
是通过类访问
的
,而不是通
浏览 2
提问于2021-01-12
得票数 1
回答已采纳
1
回答
如何用类变量解决__
getattribute__
中
的
无限递归问题
python
、
oop
、
inheritance
在子类中,我希望使基类中
的
方法
不可调用;因此,如果从子类尝试
使用
它们,我将
使用
__
getattribute__
引发
错误
。下面是一个虚拟
的
例子: class Base(object): return 1 return 2 def __
getat
浏览 19
提问于2020-09-11
得票数 0
回答已采纳
1
回答
覆盖getattr和setattr
的
基本区别
python
、
python-3.x
、
getattr
、
setattr
我
的
希望是使属性不区分大小写。我认为getattr()是__getattr__
的
一种语法糖,但它们
的
行为不同。 为什么__setattr__需要调用super(),而__getattr__不需要调用?
浏览 1
提问于2018-07-10
得票数 1
回答已采纳
4
回答
有
没有
办法不用复制
方法
在python中创建自定义字典?
python
我面临
的
问题是我
的
关键是“复制”。所以插入' copy‘键后,我无法通过getattr
方法
访问它,因为它总是返回dict
的
复制
方法
。我不能在dict上
使用
get
方法
,因为我
的
代码不知道正在传递
的
对象
的
类型
。因此,我继续
使用
getattr这一通用函数来访问属性。我还创建了一个从dict继承
的
自定义类,并编写了getattribute,但这阻止了对
方
浏览 0
提问于2019-06-26
得票数 1
回答已采纳
4
回答
了解__getattr__和__
getattribute__
之间
的
区别
python
、
oop
、
encapsulation
、
getattr
、
getattribute
我试图理解__getattr__和__
getattribute__
之间
的
区别,然而,我在这方面做得不够好。堆栈溢出问题
的
说: 我完全不知道那是什么意思。我读到如果__
getattribute__
失败,就会调用__getattr__。那么为什么会有两种不同
的
方法
做同样
的
事情呢?如果我<em
浏览 85
提问于2010-11-28
得票数 241
回答已采纳
点击加载更多
扫码
添加站长 进交流群
领取专属
10元无门槛券
手把手带您无忧上云
相关
资讯
Python基础教程
改善Python程序的91个建议(三)
Python基础-类的内置方法
Python进阶-内建函数
Python进阶——什么是描述符?
热门
标签
更多标签
云服务器
即时通信 IM
ICP备案
对象存储
实时音视频
活动推荐
运营活动
广告
关闭
领券