Rule of order for dot operators?

Chris Angelico rosuav at gmail.com
Tue May 19 02:25:35 EDT 2015


On Tue, May 19, 2015 at 12:43 PM, Ron Adam <ron3200 at gmail.com> wrote:
> Having just implementing something similar for nested scopes, it turns out
> it can't be operators because if it was, then the names y and z would be
> resolved in the wrong scope.
>
>          y = "m"
>          z = "n"
>          a = x . y . z
>
> Which of course wouldn't do what we want.
>
>          a = x . "m" . "n"
>
> And most likely this would give an error.

If you want to implement the dot as an operator, you could do it by
having a special syntactic element called an "atom", which is used for
these kinds of identifier-like tokens. The dot operator could then
take an object and an atom, and effectively return getattr(obj,
stringify(atom)). I'm fairly sure this would result in the same syntax
as Python uses.

ChrisA



More information about the Python-list mailing list