Python dot-equals (syntax proposal)

Lie Ryan lie.1296 at gmail.com
Sat May 1 15:08:53 EDT 2010


On 05/01/10 11:16, Steven D'Aprano wrote:
> On Fri, 30 Apr 2010 12:34:34 -0400, D'Arcy J.M. Cain wrote:
> 
> In practice though, I think that's a difference that makes no difference. 
> It walks like an operator, it swims like an operator, and it quacks like 
> an operator.
> 

Nope it's not. A full-time operator in python have a reflected version
(e.g. __radd__), which dot does not have. And Python's object system
makes it that the argument to __getattr__ is always a string even though
there might be a valid variable that corresponds to it:

a = MyClass()
b = MyClass()
print a . b

I've often wanted to figure out a way to (ab)use python's dot operator
for function composition (i.e. f.g(x) ==> f(g(x)) ). There's no way to
do it, not without being way too hackish. OTOH, doing so is quite
trivial with regular operators. In short, unless there's __rgetattr__
and unless you can refer to the right-hand operand as an object[1], dot
doesn't quack like an operator.

[1] well, technically string is an object, but you get what I mean



More information about the Python-list mailing list