简体   繁体   English

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

[英]In python what is the correct nomenclature for accessing a class attribute using dot notation?

This is semantics question, I'm writing a tutorial for a module that I hacked together for my lab and I would like to know if there is a correct term for accessing a class attribute by using dot notation. 这是语义问题,我正在为我的实验一起编写的模块编写教程,我想知道是否存在使用点表示法访问类属性的正确术语。 For example: 例如:

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. 名为fun的对象。

I've been using the term 'dot referencing' but that seems wrong. 我一直在使用术语“点引用”,但这似乎是错误的。 I googled around and checked the python glossary but I can't seem to find anything. 我四处搜寻并检查了python词汇表,但似乎什么也找不到。

Attribute Access, this is from the language reference section on 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. 可以定义以下方法来自定义类实例的属性访问 (使用x.name ,对其进行分配或删除)的x.name

(emphasis mine) (强调我的)

So your quote could be better worded as: 因此,您的报价可以更好地表述为:

Now, one can access the attribute attribute by using dotted expressions on the instance named fun . 现在,可以通过在名为fun的实例上使用点分表达式来访问attribute attribute

Where the term dotted expressions is found from the entry on 'attribute' in the Python Glossary . Python术语表中 “属性”的条目中可以找到术语点分表达式

Another choice employed in the docs as an alternative to dotted expressions is, as in your title, dot-notation . 在文档中采用的另一种选择可以代替点分表达式 ,例如标题中的点符号 This is found in the Callables section of the Standard Type Hierarchy , so another option you could consider is: 这可以在“ 标准类型层次结构”的“ 可调用对象”部分中找到,因此您可以考虑的另一种选择是:

Now, one can access the attribute attribute using dot-notation on the instance named fun . 现在,您可以在名为fun的实例上使用点符号访问attribute attribute

Both are, in my opinion, completely understandable if someone has at least some experience in programming languages. 我认为,如果某人至少具有一定的编程语言经验,那么两者都是完全可以理解的。 I prefer the term dot-notation and as such, would use the later. 我更喜欢术语点表示法 ,因此将在后面使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM