[Python-ideas] Object grabbing

Greg Ewing greg.ewing at canterbury.ac.nz
Sun May 1 19:56:00 EDT 2016

Robert van Geel wrote:

> using myobject:
>     .a
>     .b
>     .c()
>     .d = 1

> The rationale behind is that both typographically for the programmer this is
> more elegant than typing the variable name over and again.

Suggestions like this have been made before, and the conclusion
has always been that very little would be gained over using
a short intermediate name, e.g.

m = myobject
m.d = 1

That's just as readable and almost as easy to type. It also
has the advantage that you're not restricted to just one
"easy acess" object at a time.

The only new thing in your proposal is the change to the
bytecode, and that could be achieved by treating it as
an optimisation. A sufficiently smart code generator
could notice that you were repeatedly operating on the same
object and produce the bytecode you suggest.


More information about the Python-ideas mailing list