2

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.

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.

James Draper
  • 5,110
  • 5
  • 40
  • 59
  • 1
    «Now one can access the string by accessing the attribute attribute of the object named fun.» – Daniel Sep 16 '16 at 16:22
  • 1
    @Daniel double _attribute_ alert. – vishes_shell Sep 16 '16 at 16:24
  • accessor or getter - and with Python I usually hear this standard OOP term as "accessor" (even with other languages getter usually refers to a method over property or attribute) - [this question covers it in more detail](http://stackoverflow.com/questions/15706935/correct-way-to-use-accessors-in-python) – LinkBerest Sep 16 '16 at 16:24
  • I'd argue you don't need another verb: "Now one can access the string via the `fun` object's `attribute` attribute". A *Python* tutorial might need some way to describe or name the act of accessing an attribute, but a module tutorial can assume enough familiarity with Python to assume the reader already knows how. – chepner Sep 16 '16 at 16:40
  • @chepner that's the rub I'm trying to describe this to scientists with little to no python or OOP background so I try to make everything as simple as possible. – James Draper Sep 16 '16 at 17:06

1 Answers1

6

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.

Dimitris Fasarakis Hilliard
  • 150,925
  • 31
  • 268
  • 253