推荐人,推荐人,父母和子女 [英] Referrers, Referents, Parents and Children

查看:107
本文介绍了推荐人,推荐人,父母和子女的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试 Dill 包,特别是它检测模块并直观地遇到一些麻烦了解指称对象,指称对象,父母和子女的含义.

I'm experimenting with the Dill package, specifically it's detect module and having some trouble intuitively understanding what's is meant by referents, referers, parents and children.

引用是允许访问某些数据的值.

A reference is a value that enables access to some data.

引用对象是引用的对象,对吧?

And referents are objects that are referred to, right?

因此,在以下代码中:

class MyClass:
    """A simple example class"""
    i = 12345
    def f(self):
        return 'hello world'

an_instance = MyClass()
an_instance2 = MyClass()
an_instance3 = MyClass()

a_list = [an_instance, an_instance2, an_instance3]

a_listan_instance, an_instance2, an_instance3是指对象吗?MyClass也是a_list的对象吗?但是深度更深吗?

Are an_instance, an_instance2, an_instance3 referents of a_list and would the MyClass also be a referent of a_list, but one level of depth further up the chain?

因此,用->表示引用引用对象链会看起来像:

So, with -> signifying the reference, would the chain of referents look like:

a_list -> an_instance -> MyClass

这将被视为:

grandchild -> child -> Parent

相反,a_listan_instancean_instance2, an_instance3的引荐来源网址吗?在另一个深度级别MyClass?

Conversely, is a_list a referrer of an_instance as well as an_instance2, an_instance3 and at another level of depth, MyClass?

构成引荐来源的:

MyClass -> an_instance -> a_list

这也是可以想到的吗?

parent -> child -> grandchild

有人可以清楚地说明引用,继承和容器在哪些地方重合,哪些地方不重合?

Can someone offer a clear explanation of where references, inheritance and containers do and don't coincide?

推荐答案

在python中,继承建立了类对象和类实例对象之间的指针关系.例如,一个类实例首先检查它自己的__dict__然后指向它的类定义以查找任何缺少的属性.类似地,实例方法可以看作是应用于类方法的局部函数,再次为基础类方法提供了指针关系.使用python,继承只不过是当对象在自身内部找不到某些属性时,它会向父对象(在mro中)查找丢失的属性-该层次结构是通过指针关系构建的.

In python, inheritance builds a pointer relationship between the class object and the class instance object. For example, a class instance first checks it's own __dict__ then points back to it's class definition to find any missing attribute. Similarly, instance methods can be seen as partials that are applied over class methods, again giving a pointer relationship to the underlying class method. With python, inheritance is little more than when an object can't find some attribute within itself it looks back to the parent (in the mro) for the missing attribute -- that hierarchy is built through a pointer relationship.

大约是继承和指针引用相同的程度.指针引用更为通用.

That's about the extent that inheritance and pointer references are the same. Pointer references are much more general.

这篇关于推荐人,推荐人,父母和子女的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆