Python dot-equals (syntax proposal)

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Fri Apr 30 20:58:08 EDT 2010


On Fri, 30 Apr 2010 18:50:46 +0200, Jean-Michel Pichavant wrote:

> Jabapyth wrote:
>> At least a few times a day I wish python had the following shortcut
>> syntax:
>>
>> vbl.=func(args)
>>
>> this would be equivalent to
>>
>> vbl = vbl.func(args)
[...]
> Useless if you use meaningful names for your variables & attributes.
> 
> It may happen that one object attribute refer to an object of the same
> type, but it is quite rare that both can share the same name anyway.

How about these common operations?

my_string = my_string.replace('quite rare', 'very common')
my_string = my_string.upper()
my_string = my_string.strip()

my_dict = my_dict.copy()

Or from decimal, a whole lot of methods that return new decimals, 
including:

to_integral, next_plus, canonical, ln, sqrt, and many others.


But regardless of whether the pattern x = x.method is common or rare, I 
don't like the suggestion, I don't think it's necessary, and because of 
the moratorium it isn't going to happen any time soon even if Guido 
himself suggests it.

-1 for the suggested .= syntactic sugar.


-- 
Steven



More information about the Python-list mailing list