[Python-ideas] Keyword same in right hand side of assignments (rev)

Steven D'Aprano steve at pearwood.info
Wed Mar 18 00:29:59 CET 2009


On Tue, 17 Mar 2009 11:23:23 pm hwpuschm at yahoo.de wrote:

> What I would like is to extend the augmented assignment
> and make it easy to understand for naive readers.
[...]
> The following examples would be extensions:
>   "lst = [5,6] + same" synonymous with
>       "lst.reverse(); lst.extend([6,5]); lst.reverse()"
>   "inmutable = same*(same+1)"  synonymous with
>       "unused=inmutable+1; inmutable*=unused; del unused"
>
> There seems to be no really simple expression for the above
> extensions

Instead of the proposed "lst = [5,6] + same" or the 
obfuscated "lst.reverse(); lst.extend([6,5]); lst.reverse()", what 
about this simple assignment?

lst = [5, 6] + lst

Instead of the proposed "inmutable = same*(same+1)" or the 
obfuscated "unused=inmutable+1; inmutable*=unused; del unused", what 
about the simple:

inmutable = inmutable*(inmutable+1)

Since your claimed intention is to make it easy for naive users, why 
replace the standard idiom:

xx += 5

with an assignment containing a mysterious "same"? Many of those naive 
users will surely assume "same" is a variable name, not a magic 
keyword, and spend much time looking for where it is assigned. I 
predict that if your idea goes ahead, we'll get dozens of questions "I 
can't find where the variable same gets its value from", and we'll have 
to explain that it is a magic variable that gets its value from the 
left hand side of the assignment.

One last question -- what should happen here?

x, y, z = (same, same+1, same+2)



-- 
Steven D'Aprano



More information about the Python-ideas mailing list