红帽的Linux是不是免费的?
红帽的Linux是不是免费的?还有没有别的免费操作系统(安全性高一点的,易操作的)?
更新时间:2022-10-24 08:10
最满意答案
__getattribute__会在访问任何一个self的属性时被调用。因此在执行到self.__dict__时也会先访问__getattribute__自然就递归了。而object.__getattribute__(self, name)可以阻止。所以一般建议总是有一个地方要访问父类的__getattribute__。不过更详细的还要找相应的new-style class的文档去参考一下。
其他回答
哇塞,连风云使者都来回答我的问题,真是太感谢了啊也谢谢2楼热心的兄弟,这个论坛不错,回复很快,哈哈
相关问答
更多-
请问python中的object类有何特殊意义以及__getattribute__方法的用法[2024-03-30]
__getattribute__会在访问任何一个self的属性时被调用。因此在执行到self.__dict__时也会先访问__getattribute__自然就递归了。而object.__getattribute__(self, name)可以阻止。所以一般建议总是有一个地方要访问父类的__getattribute__。不过更详细的还要找相应的new-style class的文档去参考一下。 -
如何使用__getattribute__方法?(How do I implement __getattribute__ without an infinite recursion error?)[2023-03-17]
你得到一个递归错误,因为你调用相同的函数__getattribute__ 。 如果您使用object的__getattribute__代替,它的工作原理: class D(object): def __init__(self): self.test=20 self.test2=21 def __getattribute__(self,name): if name=='test': return 0. el ... -
python __getattribute__覆盖和@property装饰器(python __getattribute__ override and @property decorator)[2023-10-03]
我想你应该考虑在这里查看__getattr__而不是__getattribute__ 。 区别在于:如果存在__getattribute__则会被无条件地调用 - 只有在python无法通过其他方式找到属性时才会调用__getattr__ 。 I think you should probably think about looking at __getattr__ instead of __getattribute__ here. The difference is this: __getattribut ... -
您正在绕过描述符协议 ,并且您有一个未绑定的类方法。 解决方案是调用协议,如果存在__get__方法 : if hasattr(a, '__get__'): a = a.__get__(None, NothingSpecial) a() 现在classmethod绑定到类,它再次工作: >>> a.__get__(None, NothingSpecial)
> ... -
它比这更复杂一点 - Metaclasses 确实接受普通的类作为mixin,并且在这些mixins上提供的任何方法都可以在类中使用,就像它们是类方法一样(但它们将从实例中隐藏 - 作为属性在实例上查找查找类上的属性,但不查找元类上的属性)。 然而__getattribute__是一个野兽 - 即使没有涉及元类,也很难正确执行它(不像__getattr__ )。 我自己做了一些试验和错误,并且得到该type的__getattribute__存在并且与object不同 - 这就是为什么当您执行class M( ...
-
Python - 覆盖__getattribute__为一个实例?(Python - Overwriting __getattribute__ for an instance?)[2023-06-25]
我相信method-wrapper是用C语言编写的一个包装器。 I believe method-wrapper is a wrapper around a method written in C. -
实际上,在CPython中,默认的__getattribute__实现不是Python方法,而是在C中实现。它可以直接访问对象槽(C结构中表示Python对象的条目),而无需通过pesky属性访问例程。 仅仅因为你的Python代码必须这样做,并不意味着C代码必须这样做。 :-) 如果你实现了一个Python __getattribute__方法,只需使用object.__getattribute__(self, attrname) ,或者更好的是, super(YourClassName, self)._ ...
-
正如poke所说,答案是适用于所有方法。 As poke says, the answer is for all methods.
-
__getattribute__()方法用于较低级别的属性处理。 默认实现尝试在内部__dict__ (或__slots__ )中查找名称。 如果未找到该属性,则会调用__getattr__() 。 更新(如在评论中): 它们是在Python数据模型中查找属性的不同方法。 它们是内部方法,旨在在任何可能的情况下妥善回退。 线索:“机器在object.__getattribute__()将bx转换成type(b).__dict__['x'].__get__(b, type(b)) 。” 来自docs.pyth ...
-
Python:如何从__getattribute__方法访问属性(Python: how to access an attribute from a __getattribute__ method)[2023-05-08]
你的__getattribute__应该排除__dict__ ,也可以从日志中排除_log_ 。 或者,你可以做类似的事情 slog = StrLogger('foo') thelog = slog._log_ do_stuff_with(slog) print thelog (未经测试!) Your __getattribute__ should exclude __dict__ and maybe as well _log_ from logging. Alternatively, you could ...