python - 在 python 中,使用点表示法访问类属性的正确命名法是什么?

标签 python python-3.x oop

这是语义问题,我正在为我的实验室一起破解的模块编写教程,我想知道是否有使用点表示法访问类属性的正确术语。例如:

class funzo:
    def __init__(self,string):
        self.attribute = string
fun = funzo("Sweet sweet data")
fun.attribute

Now one can access the string by ??? the object named fun.

我一直在使用术语“点引用”,但这似乎是错误的。我四处搜索并检查了 python 词汇表,但我似乎找不到任何东西。

最佳答案

属性访问,这来自 customizing it 上的语言引用部分:

The following methods can be defined to customize the meaning of attribute access (use of, assignment to, or deletion of x.name) for class instances.

(强调我的)

所以你的报价可以更好地措辞为:

Now, one can access the attribute attribute by using dotted expressions on the instance named fun.

Python Glossary 的“属性”条目中找到术语点式表达式 .

文档中作为点表达式的替代方法的另一种选择是,如您的标题所示,点符号。这可以在 Standard Type HierarchyCallables 部分找到。 ,因此您可以考虑的另一个选择是:

Now, one can access the attribute attribute using dot-notation on the instance named fun.

在我看来,如果有人至少有一些编程语言经验,那么两者都是完全可以理解的。我更喜欢术语点符号,因此,会使用后者。

关于python - 在 python 中,使用点表示法访问类属性的正确命名法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39536013/

相关文章:

python - 如何修复 MatMul Op 的 float64 类型与 float32 TypeError 类型不匹配?

python - Django:以 DRY 方式按模型上定义的属性进行过滤?

python - 尽管等待 API 响应,但使用 asyncio 没有加速

python - 将破折号绘图嵌入到 html 中

java - child 没有继承其 parent 的一些属性/行为?

python - 使用 matplotlib/numpy 进行线性回归

Python 反转/反转映射(但每个键有多个值)

linux - python3中window和linux的文件路径有什么区别?

python - 我应该上课吗? (Python)

String 对象改变时的 Java String Immutability 存储