James Draper James Draper - 1 month ago 4x
Python Question

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")

Now one can access the string by ??? the object named 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.

Jim Jim

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.

(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.

Where the term dotted expressions is found from the entry on 'attribute' in the Python Glossary.

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.

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.